Skip to content

Commit

Permalink
Import of PETDANCE/WWW-Mechanize-1.56 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: WWW-Mechanize
gitpan-cpan-version:      1.56
gitpan-cpan-path:         PETDANCE/WWW-Mechanize-1.56.tar.gz
gitpan-cpan-author:       PETDANCE
gitpan-cpan-maturity:     released
  • Loading branch information
petdance authored and Gitpan committed Oct 23, 2014
1 parent 9af1071 commit c26f38c
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 63 deletions.
21 changes: 21 additions & 0 deletions Changes
Expand Up @@ -8,6 +8,27 @@ http://code.google.com/p/www-mechanize/issues/list
Mech now has its own mailing list at Google Groups:
http://groups.google.com/group/www-mechanize-users

1.56 Thu Jul 9 00:36:54 CDT 2009
========================================
[THINGS THAT MAY BREAK YOUR CODE]
For a while, Mech used HTTP::Response::Encoding to try to suss out
the proper encoding of the page it receives. Now, it lets
LWP::UserAgent do the work, and no longer requires
HTTP::Response::Encoding.

[ENHANCEMENTS]
Added a new dump_headers() method to dump the HTTP response headers.

Added --headers flag to mech-dump to dump the HTTP response headers.

[FIXES]
Now requires LWP version 5.829 because HTTP::Response has memory
cycle bugs.

[DOCUMENTATION]
Added a few notes to the FAQ, and fixed some incorrect docs.


1.55_01 Mon Jul 6 12:17:10 CDT 2009
========================================
This is mostly a bug fix release. There will be a number of other
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -15,6 +15,7 @@ lib/WWW/Mechanize/Image.pm
lib/WWW/Mechanize/Link.pm

t/TestServer.pm
t/Tools.pm

t/00-load.t
t/add_header.t
Expand Down
6 changes: 3 additions & 3 deletions META.yml
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: WWW-Mechanize
version: 1.55_01
version: 1.56
abstract: Handy web browsing in a Perl object
author:
- Andy Lester <andy@petdance.com>
Expand All @@ -25,8 +25,8 @@ requires:
HTTP::Server::Simple: 0.35
HTTP::Server::Simple::CGI: 0
HTTP::Status: 0
LWP: 5.819
LWP::UserAgent: 5.819
LWP: 5.829
LWP::UserAgent: 5.829
perl: 5.008
Pod::Usage: 0
Test::More: 0.34
Expand Down
4 changes: 2 additions & 2 deletions Makefile.PL
Expand Up @@ -43,8 +43,8 @@ my $parms = {
'HTTP::Server::Simple' => 0.35,
'HTTP::Server::Simple::CGI' => 0,
'HTTP::Status' => 0,
'LWP' => 5.819,
'LWP::UserAgent' => 5.819,
'LWP' => 5.829,
'LWP::UserAgent' => 5.829,
'Pod::Usage' => 0,
'Test::More' => 0.34,
'Test::Warn' => 0.11,
Expand Down
28 changes: 19 additions & 9 deletions bin/mech-dump
Expand Up @@ -23,10 +23,11 @@ my $agent_alias;
GetOptions(
'user=s' => \$user,
'password=s' => \$pass,
headers => sub { push( @actions, \&dump_headers ); },
forms => sub { push( @actions, \&dump_forms ); },
links => sub { push( @actions, \&dump_links ); },
images => sub { push( @actions, \&dump_images ); },
all => sub { push( @actions, \&dump_forms, \&dump_links, \&dump_images ); },
all => sub { push( @actions, \&dump_headers, \&dump_forms, \&dump_links, \&dump_images ); },
absolute => \$absolute,
'agent=s' => \$agent,
'agent-alias=s' => \$agent_alias,
Expand All @@ -39,10 +40,11 @@ mech-dump [options] [file|url]
Options:
--headers Dump HTTP response headers
--forms Dump table of forms (default action)
--links Dump table of links
--images Dump table of images
--all Dump all three of the above, in that order
--all Dump all four of the above, in that order
--user=user Set the username
--password=pass Set the password
Expand Down Expand Up @@ -93,24 +95,32 @@ if (!$response->is_success and defined ($response->www_authenticate)) {
}
$mech->is_html or die qq{$uri returns type "}, $mech->ct, qq{", not "text/html"\n};

for my $action ( @actions ) {
while ( my $action = shift @actions ) {
$action->( $mech );
print "\n" if @actions;
}

sub dump_links {

sub dump_headers {
my $mech = shift;
$mech->dump_links( undef, $absolute );
$mech->dump_headers( undef );
return;
}

sub dump_images {
sub dump_forms {
my $mech = shift;
$mech->dump_images( undef, $absolute );
$mech->dump_forms( undef, $absolute );
return;
}

sub dump_forms {
sub dump_links {
my $mech = shift;
$mech->dump_forms( undef, $absolute );
$mech->dump_links( undef, $absolute );
return;
}

sub dump_images {
my $mech = shift;
$mech->dump_images( undef, $absolute );
return;
}
55 changes: 41 additions & 14 deletions lib/WWW/Mechanize.pm
Expand Up @@ -6,11 +6,11 @@ WWW::Mechanize - Handy web browsing in a Perl object
=head1 VERSION
Version 1.55_01
Version 1.56
=cut

our $VERSION = '1.55_01';
our $VERSION = '1.56';

=head1 SYNOPSIS
Expand Down Expand Up @@ -103,10 +103,9 @@ use strict;
use warnings;

use HTTP::Request 1.30;
use LWP::UserAgent 2.003;
use LWP::UserAgent 5.827;
use HTML::Form 1.00;
use HTML::TokeParser;
use HTTP::Response::Encoding 0.05;

use base 'LWP::UserAgent';

Expand Down Expand Up @@ -204,6 +203,10 @@ history.
=back
To support forms, WWW::Mechanize's constructor pushes POST
on to the agent's C<requests_redirectable> list (see also
L<LWP::UserAgent>.)
=cut

sub new {
Expand Down Expand Up @@ -954,19 +957,15 @@ then the return will be an empty array.
You may use a regex or a literal string:
# get all textarea controls whose names begin with "customer"
my @customer_text_inputs =
$mech->find_all_inputs( {
type => 'textarea',
name_regex => qr/^customer/,
}
my @customer_text_inputs = $mech->find_all_inputs(
type => 'textarea',
name_regex => qr/^customer/,
);
# get all text or textarea controls called "customer"
my @customer_text_inputs =
$mech->find_all_inputs( {
type_regex => qr/^(text|textarea)$/,
name => 'customer',
}
my @customer_text_inputs = $mech->find_all_inputs(
type_regex => qr/^(text|textarea)$/,
name => 'customer',
);
=cut
Expand Down Expand Up @@ -1978,6 +1977,28 @@ sub save_content {
return;
}


=head2 $mech->dump_headers( [$fh] )
Prints a dump of the HTTP response headers for the most recent
response. If I<$fh> is not specified or is undef, it dumps to
STDOUT.
Unlike the rest of the dump_* methods, you cannot specify a filehandle
to print to.
=cut

sub dump_headers {
my $self = shift;
my $fh = shift || \*STDOUT;

print {$fh} $self->response->headers_as_string;

return;
}


=head2 $mech->dump_links( [[$fh], $absolute] )
Prints a dump of the links on the current page to I<$fh>. If I<$fh>
Expand Down Expand Up @@ -2086,6 +2107,9 @@ An overloaded version of C<redirect_ok()> in L<LWP::UserAgent>.
This method is used to determine whether a redirection in the request
should be followed.
Note that WWW::Mechanize's constructor pushes POST on to the agent's
C<requests_redirectable> list.
=cut

sub redirect_ok {
Expand Down Expand Up @@ -2794,6 +2818,9 @@ Just like Mech, but using Microsoft Internet Explorer to do the work.
Thanks to the numerous people who have helped out on WWW::Mechanize in
one way or another, including
Kirrily Robert for the original C<WWW::Automate>,
Jeremy Ary,
Hilary Holz,
Rafael Kitover,
Norbert Buchmuller,
Dave Page,
David Sainty,
Expand Down
35 changes: 35 additions & 0 deletions lib/WWW/Mechanize/FAQ.pod
Expand Up @@ -166,6 +166,13 @@ Use the mech-dump utility, optionaly installed with Mechanize.
$agent->credentials( ADDRESS, REALM, USER, PASS );
$agent->get( URL, @args );

If you want to use the credentials for all future requests, you can
also use the L<LWP::UserAgent> C<default_header()> method instead
of the extra arguments to C<get()>

$mech->default_header(
Authorization => 'Basic ' . encode_base64( USER . ':' . PASSWORD ) );

=head2 How can I get WWW::Mechanize to execute this JavaScript?

You can't. JavaScript is entirely client-based, and WWW::Mechanize
Expand Down Expand Up @@ -198,6 +205,34 @@ I<submit_form()>, and I<request()> methods.
print $key, " : ", $response->header( $key ), "\n";
}

=head2 How do I enable keep-alive?

Since L<WWW::Mechanize> is a subclass of L<LWP::UserAgent>, you can
use the same mechanism to enable keep-alive:

use LWP::ConnCache;
...
$mech->conn_cache(LWP::ConnCache->new);

=head2 How can I change/specify the action parameter of an HTML form?

You can access the action of the form by utilizing the L<HTML::Form>
object returned from one of the specifying form methods.

Using C<< $mech->form_number($number) >>:

my $mech = WWW::mechanize->new;
$mech->get('http://someurlhere.com');
# Access the form using its Zero-Based Index by DOM order
$mech->form_number(0)->action('http://newAction'); #ABS URL

Using C<< $mech->form_name($number) >>:

my $mech = WWW::mechanize->new;
$mech->get('http://someurlhere.com');
#Access the form using its Zero-Based Index by DOM order
$mech->form_name('trgForm')->action('http://newAction'); #ABS URL

=head1 Why doesn't this work: Debugging your Mechanize program

=head2 My Mech program doesn't work, but it works in the browser.
Expand Down
8 changes: 8 additions & 0 deletions t/00-load.t
Expand Up @@ -2,9 +2,17 @@

use warnings;
use strict;
use lib 't';
use Test::More tests => 2;
use Tools;

use_ok( 'WWW::Mechanize' );
use_ok( 'WWW::Mechanize::Link' );

diag( "Testing WWW::Mechanize $WWW::Mechanize::VERSION, with LWP $LWP::VERSION, Perl $], $^X" );
if ( $canTMC ) {
diag( "Test::Memory::Cycle $Test::Memory::Cycle::VERSION is installed." );
}
else {
diag( 'Test::Memory::Cycle is not installed.' );
}
20 changes: 20 additions & 0 deletions t/Tools.pm
@@ -0,0 +1,20 @@
package Tools;

use base 'Exporter';

our @EXPORT_OK = qw( $canTMC memory_cycle_ok );
our @EXPORT = @EXPORT_OK;

our $canTMC;

sub import {
delete @ENV{ qw( http_proxy HTTP_PROXY PATH IFS CDPATH ENV BASH_ENV) };

eval 'use Test::Memory::Cycle';
$canTMC = !$@;

Tools->export_to_level(1, @_);
}


1;
11 changes: 7 additions & 4 deletions t/area_link.t
Expand Up @@ -4,15 +4,18 @@
use warnings;
use strict;
use Test::More tests => 9;
use URI::file;

BEGIN { delete @ENV{ qw( http_proxy HTTP_PROXY PATH IFS CDPATH ENV BASH_ENV) }; }
use lib 't';

BEGIN {
use Tools;
}

BEGIN {
use_ok( 'WWW::Mechanize' );
}

eval 'use Test::Memory::Cycle';
my $canTMC = !$@;
use URI::file;

my $mech = WWW::Mechanize->new( cookie_jar => undef );
isa_ok( $mech, 'WWW::Mechanize' );
Expand Down
5 changes: 3 additions & 2 deletions t/live/encoding.t
Expand Up @@ -7,7 +7,7 @@ use constant PAIRS => {
'http://delicious.com/'
=> 'utf-8',
'http://www.liveinternet.ru/users/dashdi/blog'
=> 'cp1251',
=> '(?:cp|windows-)1251',
'http://oops-music.com/'
=> 'EUC-JP',
};
Expand All @@ -29,6 +29,7 @@ for my $url ( sort keys %pairs ) {
$mech->get( $url );
is( $mech->response->code, 200, "Fetched $url" );

like( $mech->res->encoding, qr/$want_encoding/i, " ... Got encoding $want_encoding" );
like( $mech->res->content_charset, qr/$want_encoding/i,
" ... Got encoding $want_encoding" );
ok( Encode::is_utf8( $mech->content ), 'Got back UTF-8' );
}
9 changes: 7 additions & 2 deletions t/live/wikipedia.t
Expand Up @@ -6,6 +6,12 @@ use strict;
use constant LANGUAGES => qw( en it ja es nl pl );
use Test::More tests => 3 + (2 * scalar LANGUAGES);

use lib 't';

BEGIN {
use Tools;
}

BEGIN {
use_ok( 'WWW::Mechanize' );
}
Expand All @@ -25,8 +31,7 @@ for my $lang ( LANGUAGES ) {
}

SKIP: {
eval 'use Test::Memory::Cycle';
skip 'Test::Memory::Cycle not installed', 1 if $@;
skip 'Test::Memory::Cycle not installed', 1 unless $canTMC;

memory_cycle_ok( $mech, 'No memory cycles found' );
}
Expand Down

0 comments on commit c26f38c

Please sign in to comment.