3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
8 mech-dump - Dumps information about a web page
28 'password=s' => \$pass,
29 forms => sub { push( @actions, \&dump_forms ); },
30 links => sub { push( @actions, \&dump_links ); },
31 images => sub { push( @actions, \&dump_images ); },
32 all => sub { push( @actions, \&dump_forms, \&dump_links, \&dump_images ); },
33 absolute => \$absolute,
35 'agent-alias=s' => \$agent_alias,
36 help => sub { pod2usage(1); },
41 mech-dump [options] [file|url]
45 --forms Dump table of forms (default action)
46 --links Dump table of links
47 --images Dump table of images
48 --all Dump all three of the above, in that order
50 --user=user Set the username
51 --password=pass Set the password
53 --agent=agent Specify the UserAgent to pass
55 Specify the alias for the UserAgent to pass.
64 --absolute Show URLs as absolute, even if relative in the page
65 --help Show this message
67 The order of the options specified is relevant. Repeated options
72 my $uri = shift or die "Must specify a URL or file to check. See --help for details.\n";
75 $uri = URI::file->new_abs( $uri )->as_string;
78 @actions = (\&dump_forms) unless @actions;
80 my $mech = WWW::Mechanize->new( cookie_jar => undef );
81 if ( defined $agent ) {
82 $mech->agent( $agent );
84 elsif ( defined $agent_alias ) {
85 $mech->agent_alias( $agent_alias );
88 my $response = $mech->get( $uri );
89 if (!$response->is_success and defined ($response->www_authenticate)) {
90 if (!defined $user or !defined $pass) {
91 die("Page requires username and password, but none specified.\n");
93 $mech->credentials($user,$pass);
94 $response = $mech->get( $uri );
95 $response->is_success or die "Can't fetch $uri with username and password\n", $response->status_line, "\n";
97 $mech->is_html or die qq{$uri returns type "}, $mech->ct, qq{", not "text/html"\n};
99 for my $action ( @actions ) {
105 $mech->dump_links( undef, $absolute );
111 $mech->dump_images( undef, $absolute );
117 $mech->dump_forms( undef, $absolute );