Skip to content

Commit

Permalink
added mech-dump --text
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Sep 10, 2010
1 parent 95b0b5b commit 9c0efd3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Schwern.
[ENHANCEMENTS] [ENHANCEMENTS]
New $mech->text method returns the text from your HTML page. The New $mech->text method returns the text from your HTML page. The
exact rendering of this text is simply removing all the HTML exact rendering of this text is simply removing all the HTML
tags, but this may change. tags, but this will change. It's pretty ugly.

Added mech-dump --text.


[DOCUMENTATION] [DOCUMENTATION]
Improvements to the docs explaining explicitly about the subclassed Improvements to the docs explaining explicitly about the subclassed
Expand Down
19 changes: 14 additions & 5 deletions bin/mech-dump
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ my $cookie_filename;
GetOptions( GetOptions(
'user=s' => \$user, 'user=s' => \$user,
'password=s' => \$pass, 'password=s' => \$pass,
headers => sub { push( @actions, \&dump_headers ); }, headers => sub { push( @actions, \&dump_headers ) },
forms => sub { push( @actions, \&dump_forms ); }, forms => sub { push( @actions, \&dump_forms ) },
links => sub { push( @actions, \&dump_links ); }, links => sub { push( @actions, \&dump_links ) },
images => sub { push( @actions, \&dump_images ); }, images => sub { push( @actions, \&dump_images ) },
all => sub { push( @actions, \&dump_headers, \&dump_forms, \&dump_links, \&dump_images ); }, all => sub { push( @actions, \&dump_headers, \&dump_forms, \&dump_links, \&dump_images ) },
text => sub { push( @actions, \&dump_text ) },
absolute => \$absolute, absolute => \$absolute,
'agent=s' => \$agent, 'agent=s' => \$agent,
'agent-alias=s' => \$agent_alias, 'agent-alias=s' => \$agent_alias,
Expand All @@ -49,6 +50,8 @@ Options:
--images Dump table of images --images Dump table of images
--all Dump all four of the above, in that order --all Dump all four of the above, in that order
--text Dumps the textual part of the web page
--user=user Set the username --user=user Set the username
--password=pass Set the password --password=pass Set the password
--cookie-file=filename Set the filename to use for persistent cookies --cookie-file=filename Set the filename to use for persistent cookies
Expand Down Expand Up @@ -138,6 +141,12 @@ sub dump_images {
return; return;
} }


sub dump_text {
my $mech = shift;
$mech->dump_text();
return;
}

=head1 SEE ALSO =head1 SEE ALSO
L<WWW::Mechanize> L<WWW::Mechanize>
14 changes: 5 additions & 9 deletions lib/WWW/Mechanize.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2126,23 +2126,19 @@ sub dump_forms {
return; return;
} }


=head2 $mech->dump_all( [[$fh], $absolute] ) =head2 $mech->dump_text( [$fh] )
Prints a dump of all links, images and forms on the current page to Prints a dump of the text on the current page to I<$fh>. If I<$fh>
I<$fh>. If I<$fh> is not specified or is undef, it dumps to STDOUT. is not specified or is undef, it dumps to STDOUT.
If I<$absolute> is true, links displayed are absolute, not relative.
=cut =cut


sub dump_all { sub dump_text {
my $self = shift; my $self = shift;
my $fh = shift || \*STDOUT; my $fh = shift || \*STDOUT;
my $absolute = shift; my $absolute = shift;


$self->dump_links( $fh, $absolute ); print {$fh} $self->text, "\n";
$self->dump_images( $fh, $absolute );
$self->dump_forms( $fh, $absolute );


return; return;
} }
Expand Down
14 changes: 9 additions & 5 deletions tags
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ LocalServer t/local/LocalServer.pm /^package LocalServer;$/;" p
MY Makefile.PL /^sub MY::postamble {$/;" s MY Makefile.PL /^sub MY::postamble {$/;" s
MyMech t/local/overload.t /^ package MyMech;$/;" p MyMech t/local/overload.t /^ package MyMech;$/;" p
NEW_API t/link.t /^NEW_API: {$/;" l NEW_API t/link.t /^NEW_API: {$/;" l
NONEXISTENT t/autocheck.t /^use constant NONEXISTENT => 'http:\/\/blahblablah.xx-nonexistent.';$/;" c
NON_REGEX_STRING t/find_link-warnings.t /^NON_REGEX_STRING: {$/;" l NON_REGEX_STRING t/find_link-warnings.t /^NON_REGEX_STRING: {$/;" l
NO_AGENT t/new.t /^NO_AGENT: {$/;" l NO_AGENT t/new.t /^NO_AGENT: {$/;" l
NO_BASE t/link-base.t /^NO_BASE: {$/;" l NO_BASE t/link-base.t /^NO_BASE: {$/;" l
Expand Down Expand Up @@ -74,11 +73,10 @@ WWW::Mechanize::Link lib/WWW/Mechanize/Link.pm /^package WWW::Mechanize::Link;$/
_SUPER_put lib/WWW/Mechanize.pm /^sub _SUPER_put {$/;" s _SUPER_put lib/WWW/Mechanize.pm /^sub _SUPER_put {$/;" s
_check_unhandled_parms lib/WWW/Mechanize.pm /^sub _check_unhandled_parms {$/;" s _check_unhandled_parms lib/WWW/Mechanize.pm /^sub _check_unhandled_parms {$/;" s
_clean_keys lib/WWW/Mechanize.pm /^sub _clean_keys {$/;" s _clean_keys lib/WWW/Mechanize.pm /^sub _clean_keys {$/;" s
_content_as_text lib/WWW/Mechanize.pm /^sub _content_as_text {$/;" s
_die lib/WWW/Mechanize.pm /^sub _die {$/;" s _die lib/WWW/Mechanize.pm /^sub _die {$/;" s
_extract_forms lib/WWW/Mechanize.pm /^sub _extract_forms {$/;" s
_extract_images lib/WWW/Mechanize.pm /^sub _extract_images {$/;" s _extract_images lib/WWW/Mechanize.pm /^sub _extract_images {$/;" s
_extract_links lib/WWW/Mechanize.pm /^sub _extract_links {$/;" s _extract_links lib/WWW/Mechanize.pm /^sub _extract_links {$/;" s
_format_content lib/WWW/Mechanize.pm /^sub _format_content {$/;" s
_image_from_token lib/WWW/Mechanize.pm /^sub _image_from_token {$/;" s _image_from_token lib/WWW/Mechanize.pm /^sub _image_from_token {$/;" s
_is_tainted lib/WWW/Mechanize.pm /^sub _is_tainted {$/;" s _is_tainted lib/WWW/Mechanize.pm /^sub _is_tainted {$/;" s
_link_from_token lib/WWW/Mechanize.pm /^sub _link_from_token {$/;" s _link_from_token lib/WWW/Mechanize.pm /^sub _link_from_token {$/;" s
Expand Down Expand Up @@ -111,18 +109,23 @@ credentials lib/WWW/Mechanize.pm /^sub credentials {$/;" s
creds_required t/local/LocalServer.pm /^sub creds_required {$/;" s creds_required t/local/LocalServer.pm /^sub creds_required {$/;" s
critic Makefile.PL /^critic:$/;" l critic Makefile.PL /^critic:$/;" l
ct lib/WWW/Mechanize.pm /^sub ct { my $self = shift; return $self->{ct}; }$/;" s ct lib/WWW/Mechanize.pm /^sub ct { my $self = shift; return $self->{ct}; }$/;" s
current_form lib/WWW/Mechanize.pm /^sub current_form { my $self = shift; return $self->{form}; }$/;" s current_form lib/WWW/Mechanize.pm /^sub current_form {$/;" s
delete_header lib/WWW/Mechanize.pm /^sub delete_header {$/;" s delete_header lib/WWW/Mechanize.pm /^sub delete_header {$/;" s
die lib/WWW/Mechanize.pm /^sub die {$/;" s die lib/WWW/Mechanize.pm /^sub die {$/;" s
dump_all lib/WWW/Mechanize.pm /^sub dump_all {$/;" s
dump_forms bin/mech-dump /^sub dump_forms {$/;" s dump_forms bin/mech-dump /^sub dump_forms {$/;" s
dump_forms bin/mech-dump.orig /^sub dump_forms {$/;" s
dump_forms lib/WWW/Mechanize.pm /^sub dump_forms {$/;" s dump_forms lib/WWW/Mechanize.pm /^sub dump_forms {$/;" s
dump_headers bin/mech-dump /^sub dump_headers {$/;" s dump_headers bin/mech-dump /^sub dump_headers {$/;" s
dump_headers bin/mech-dump.orig /^sub dump_headers {$/;" s
dump_headers lib/WWW/Mechanize.pm /^sub dump_headers {$/;" s dump_headers lib/WWW/Mechanize.pm /^sub dump_headers {$/;" s
dump_images bin/mech-dump /^sub dump_images {$/;" s dump_images bin/mech-dump /^sub dump_images {$/;" s
dump_images bin/mech-dump.orig /^sub dump_images {$/;" s
dump_images lib/WWW/Mechanize.pm /^sub dump_images {$/;" s dump_images lib/WWW/Mechanize.pm /^sub dump_images {$/;" s
dump_links bin/mech-dump /^sub dump_links {$/;" s dump_links bin/mech-dump /^sub dump_links {$/;" s
dump_links bin/mech-dump.orig /^sub dump_links {$/;" s
dump_links lib/WWW/Mechanize.pm /^sub dump_links {$/;" s dump_links lib/WWW/Mechanize.pm /^sub dump_links {$/;" s
dump_text bin/mech-dump /^sub dump_text {$/;" s
dump_text lib/WWW/Mechanize.pm /^sub dump_text {$/;" s
field lib/WWW/Mechanize.pm /^sub field {$/;" s field lib/WWW/Mechanize.pm /^sub field {$/;" s
find_all_images lib/WWW/Mechanize.pm /^sub find_all_images {$/;" s find_all_images lib/WWW/Mechanize.pm /^sub find_all_images {$/;" s
find_all_inputs lib/WWW/Mechanize.pm /^sub find_all_inputs {$/;" s find_all_inputs lib/WWW/Mechanize.pm /^sub find_all_inputs {$/;" s
Expand Down Expand Up @@ -183,6 +186,7 @@ success lib/WWW/Mechanize.pm /^sub success {$/;" s
tag lib/WWW/Mechanize/Image.pm /^sub tag { return ($_[0])->{tag}; }$/;" s tag lib/WWW/Mechanize/Image.pm /^sub tag { return ($_[0])->{tag}; }$/;" s
tag lib/WWW/Mechanize/Link.pm /^sub tag { return ($_[0])->[3]; }$/;" s tag lib/WWW/Mechanize/Link.pm /^sub tag { return ($_[0])->[3]; }$/;" s
tags Makefile.PL /^tags:$/;" l tags Makefile.PL /^tags:$/;" l
text lib/WWW/Mechanize.pm /^sub text {$/;" s
text lib/WWW/Mechanize/Link.pm /^sub text { return ($_[0])->[1]; }$/;" s text lib/WWW/Mechanize/Link.pm /^sub text { return ($_[0])->[1]; }$/;" s
tick lib/WWW/Mechanize.pm /^sub tick {$/;" s tick lib/WWW/Mechanize.pm /^sub tick {$/;" s
title lib/WWW/Mechanize.pm /^sub title {$/;" s title lib/WWW/Mechanize.pm /^sub title {$/;" s
Expand Down

0 comments on commit 9c0efd3

Please sign in to comment.