Subject: | PATCH: let get() work as a class method |
The attached code/test/doc patch simplies this idiom:
my $mech = WWW::Mechanize->new();
$mech->get($uri);
To just:
my $mech = WWW::Mechanize->get($uri);
Mark
Subject: | mech_get.diff |
297a298,299
> =head2 $mech = WWW::Mechanize->get( $url )
>
303a306,308
> If called as a class method, it's the same as first calling C<new()> with
> no arguments.
>
319c324
< my $self = shift;
---
> my $self_or_class = shift;
320a326,336
>
> my $self;
> my $already_obj = (ref $self_or_class);
> if ($already_obj) {
> $self = $self_or_class;
> }
> else {
> my $class = $self_or_class;
> $self = $class->new();
> }
>
Subject: | get.t |
#!perl -Tw
use warnings;
use strict;
use URI::file;
use Test::More 'no_plan';
BEGIN {
use_ok('WWW::Mechanize');
}
my $uri = URI::file->new_abs( "t/image-parse.html" )->as_string;
my $mech;
eval { $mech = WWW::Mechanize->get( $uri ); };
is($@,'','survived eval');
isa_ok( $mech, 'HTTP::Response', "get works as a class method" );