5 mech-dump - Dumps information about a web page
25 'password=s' => \$pass,
26 forms => sub { push( @actions, \&dump_forms ); },
27 links => sub { push( @actions, \&dump_links ); },
28 images => sub { push( @actions, \&dump_images ); },
29 all => sub { push( @actions, \&dump_forms, \&dump_links, \&dump_images ); },
30 absolute => \$absolute,
32 'agent-alias=s' => \$agent_alias,
33 help => sub { pod2usage(1); },
38 mech-dump [options] [file|url]
42 --forms Dump table of forms (default action)
43 --links Dump table of links
44 --images Dump table of images
45 --all Dump all three of the above, in that order
47 --user=user Set the username
48 --password=pass Set the password
50 --agent=agent Specify the UserAgent to pass
52 Specify the alias for the UserAgent to pass.
61 --absolute Show URLs as absolute, even if relative in the page
62 --help Show this message
64 The order of the options specified is relevant. Repeated options
69 my $uri = shift or die "Must specify a URL or file to check. See --help for details.\n";
72 $uri = URI::file->new_abs( $uri )->as_string;
75 @actions = (\&dump_forms) unless @actions;
77 my $mech = WWW::Mechanize->new( cookie_jar => undef );
78 if ( defined $agent ) {
79 $mech->agent( $agent );
81 elsif ( defined $agent_alias ) {
82 $mech->agent_alias( $agent_alias );
85 my $response = $mech->get( $uri );
86 if (!$response->is_success and defined ($response->www_authenticate)) {
87 if (!defined $user or !defined $pass) {
88 die("Page requires username and password, but none specified.\n");
90 $mech->credentials($user,$pass);
91 $response = $mech->get( $uri );
92 $response->is_success or die "Can't fetch $uri with username and password\n", $response->status_line, "\n";
94 $mech->is_html or die qq{$uri returns type "}, $mech->ct, qq{", not "text/html"\n};
96 for my $action ( @actions ) {
102 $mech->dump_links( undef, $absolute );
108 $mech->dump_images( undef, $absolute );
114 $mech->dump_forms( undef, $absolute );