Well, you must have several cookies in the cookie jar in order to view the output cookies. So far, you have an empty cookie jar. Either make sure that you have added several cookies, or that the site you are accessing sets them:
use HTTP::Cookies;
use WWW::Mechanize;
my $cookie_jar = HTTP::Cookies->new;
my $agent = WWW::Mechanize->new( cookie_jar => $cookie_jar );
$cookie_jar->set_cookie(
qw(
3
cat
buster
/
.example.com
0
0
0
)
);
$agent->get( 'http://www.amazon.com' );
print "Set Cookie Jar?\n", $agent->cookie_jar->as_string, "\n";
This gave me the result:
Set Cookie Jar?
Set-Cookie3: session-id=000-0000000-0000000; path="/"; domain=.amazon.com; path_spec; discard; version=0
Set-Cookie3: session-id-time=1272524400l; path="/"; domain=.amazon.com; path_spec; discard; version=0 Set-Cookie3: cat=buster; path="/"; domain=.example.com; port=0; version=3
However, you do not need to refer directly to HTTP::Cookies. LWPwill take care of that. You just pass the cookie_jarhash link:
my $agent = WWW::Mechanize->new( cookie_jar => {} );
, cookie , cookie , :
use WWW::Mechanize;
my $agent = WWW::Mechanize->new( cookie_jar => {} );
my $response = $agent->get( 'http://www.amazon.com' );
my $cookie_jar = HTTP::Cookies->new;
$cookie_jar->extract_cookies( $response );
print $cookie_jar->as_string;