WWW-Mechanize-FormFiller-0.13/0000755000175000017500000000000014276737724015450 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/MANIFEST.SKIP0000755000175000017500000000023313040205704017317 0ustar corioncorion^.cvsignore ^t/.cvsignore ^.lwpcookies ^.releaserc ^blib/ ^WWW-Mechanize-FormFiller-.* CVS/ \.git/ ^pm_to_blib .tar.gz$ .old$ ^Makefile$ .*.bak MYMETA\..* WWW-Mechanize-FormFiller-0.13/Makefile.PL0000755000175000017500000000356713040205704017410 0ustar corioncorionuse ExtUtils::MakeMaker; use lib 'lib'; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'WWW::Mechanize::FormFiller', 'VERSION_FROM' => 'lib/WWW/Mechanize/FormFiller.pm', # finds $VERSION 'PREREQ_PM' => { 'HTML::Form' => 0, 'Test::More' => 0, 'HTML::Tagset' => 0, 'Data::Random' => 0.05, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/WWW/Mechanize/FormFiller.pm', # retrieve abstract from module AUTHOR => 'Max Maischein ') : ()), ); use vars qw($have_test_inline); BEGIN { eval { require Test::Inline; $have_test_inline = $Test::Inline::VERSION ge '0.15_001'; }; undef $@; if ($have_test_inline) { print "Good - you have a patched Test::Inline\n"; } else { print "Test::Inline 0.15_001 is nice for testing the examples, but not necessary\n" }; }; # Autocreate the synopsis test from the pod of every module # (if we have Test::Inline) if (0) { eval q{ package MY; use strict; sub top_targets { my($self) = @_; my $out = "POD2TEST_EXE = pod2test\n"; $out .= $self->SUPER::top_targets(@_); return $out unless $main::have_test_inline; $out =~ s/^(pure_all\b.*)/$1 testifypods/m; $out .= "\n\ntestifypods : \n"; foreach my $pod (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) { (my $test = $pod) =~ s/\.(pm|pod)$//; $test =~ s|/|-|g; $test =~ s/^lib\W//; $test =~ s/\W/-/; $test = "embedded-$test.t"; $out .= "\t$self->{NOECHO}\$(POD2TEST_EXE) ". "$pod t/$test\n"; } return $out; } }} # To make Test::Prereq happy 1; WWW-Mechanize-FormFiller-0.13/t/0000755000175000017500000000000014276737724015713 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/t/05-Form-1.t0000755000175000017500000000606113040205704017341 0ustar corioncorionuse strict; my @tests; BEGIN{ @tests = ( # Class, name,args, html index, expected value ['Fixed',"text_input_1",["bar"],0,"bar"], ['Fixed',"text_input_2",["bar"],1,"bar"], ['Fixed',"radio",["0"],2,"0"], ['Fixed',"radio",["1"],2,"1"], ['Fixed',"radio",["2"],2,"2"], ['Fixed',"radio",["3"],2,"3"], ['Fixed',"checkbox_1",[""],3,undef], ['Fixed',"checkbox_1",["on"],3,"on"], ['Fixed',"checkbox_2",[""],4,undef], ['Fixed',"checkbox_2",["on"],4,"on"], ['Default',"text_input_1",["bar"],0,"bar"], ['Default',"text_input_2",["bar"],1,"xxx"], ['Default',"radio",["0"],2,"1"], ['Default',"radio",["1"],2,"1"], ['Default',"radio",["2"],2,"1"], ['Default',"radio",["3"],2,"1"], ['Default',"checkbox_1",[""],3,"on"], ['Default',"checkbox_1",["on"],3,"on"], ['Default',"checkbox_2",[""],4,undef], # ??? This is a bit weird, but that's OK at the moment ['Default',"checkbox_2",["on"],4,"on"], # REs ['Fixed',qr/text_input/,["bar"],0,"bar"], ['Fixed',qr/text_input/,["bar"],1,"bar"], ); }; use Test::More tests => 1 + scalar @tests * 3; BEGIN { use_ok("WWW::Mechanize::FormFiller"); }; SKIP: { eval { require HTML::Form }; skip "Need HTML::Form to run the more extensive tests", scalar @tests * 3 if $@; # Load the different HTML sets my @forms = split /---/, do { local $/ = undef; ; }; for my $row (@tests) { my ($class,$name,$args,$index,$expected) = @$row; my $f = WWW::Mechanize::FormFiller->new(); isa_ok($f,"WWW::Mechanize::FormFiller"); my $form = HTML::Form->parse($forms[$index],"http://www.nowhere.org"); my $filler = $f->add_filler($name,$class,@$args); isa_ok($filler, "WWW::Mechanize::FormFiller::Value::$class"); $f->fill_form($form); my @filled_inputs; if (ref $name and UNIVERSAL::isa( $name,'Regexp')) { @filled_inputs = grep { $_->name =~ $name } $form->inputs; } else { @filled_inputs = $form->find_input($name); }; for my $input (@filled_inputs) { is($input->value,$expected,"Modified the expected field for page $index/$name ($class:".join(":",@$args).")"); }; }; }; __DATA__ Text box
--- Text box (prefilled)
--- Radio box
--- Readonly checkbox
--- Readonly checkbox
WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Random-Date.t0000644000175000017500000001000113040205704027356 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Random/Date.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Date eval { require WWW::Mechanize::FormFiller::Value::Random::Date }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Date to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 56 lib/WWW/Mechanize/FormFiller/Value/Random/Date.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Date; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "born" my $born = WWW::Mechanize::FormFiller::Value::Random::Date->new( born => string => '%Y%m%d', min => '20000101', max => '20373112' ); $f->add_value( born => $born ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $last_here = $f->add_filler( last_here => Random::Date => string => '%H%M%S', min => '000000', max => 'now'); ; } }; is($@, '', "example from line 56"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Date eval { require WWW::Mechanize::FormFiller::Value::Random::Date }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Date to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 56 lib/WWW/Mechanize/FormFiller/Value/Random/Date.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Date; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "born" my $born = WWW::Mechanize::FormFiller::Value::Random::Date->new( born => string => '%Y%m%d', min => '20000101', max => '20373112' ); $f->add_value( born => $born ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $last_here = $f->add_filler( last_here => Random::Date => string => '%H%M%S', min => '000000', max => 'now'); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('born'), qr/^(\d{8})$/, "born gets set"); like( $form->value('last_here'), qr/^(\d{6})$/, "last_here gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Fixed.t0000644000175000017500000000714113040205704026335 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Fixed.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Fixed eval { require WWW::Mechanize::FormFiller::Value::Fixed }; skip "Need module WWW::Mechanize::FormFiller::Value::Fixed to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 28 lib/WWW/Mechanize/FormFiller/Value/Fixed.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Fixed; my $f = WWW::Mechanize::FormFiller->new(); # Create a fixed value for the HTML field "login" my $fixed = WWW::Mechanize::FormFiller::Value::Fixed->new( login => "Corion" ); $f->add_value( login => $fixed ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $password = $f->add_filler( password => Fixed => "secret" ); ; } }; is($@, '', "example from line 28"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Fixed eval { require WWW::Mechanize::FormFiller::Value::Fixed }; skip "Need module WWW::Mechanize::FormFiller::Value::Fixed to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 28 lib/WWW/Mechanize/FormFiller/Value/Fixed.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Fixed; my $f = WWW::Mechanize::FormFiller->new(); # Create a fixed value for the HTML field "login" my $fixed = WWW::Mechanize::FormFiller::Value::Fixed->new( login => "Corion" ); $f->add_value( login => $fixed ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $password = $f->add_filler( password => Fixed => "secret" ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Corion", "Login gets set"); is( $form->value('password'), "secret", "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/06-Form-Image-Button.t0000755000175000017500000000350313040205704021473 0ustar corioncorionuse strict; use Test::More tests => 7; use_ok("WWW::Mechanize::FormFiller"); SKIP: { eval { require HTML::Form }; skip "Need HTML::Form to run the form image value test", 6 if $@; eval { require Test::MockObject }; skip "Need Test::MockObject to run the form image value test", 6 if $@; { my $f = WWW::Mechanize::FormFiller->new(); isa_ok($f,"WWW::Mechanize::FormFiller"); my $value = $f->add_value("image1", Test::MockObject->new()->set_always('value','Returned Value')); my $form = HTML::Form->parse(<
HTML $f->fill_form($form); my ($method,$args) = $value->next_call; is($method,"value","Image inputs get called if they are specified"); my $filled_input = $form->find_input("image1"); is($filled_input->value, 'Returned Value', "Returned image values get set") }; { my $value = Test::MockObject->new()->set_always('value','Returned Value'); $value->fake_module('WWW::Mechanize::FormFiller::Value::Test'); $value->fake_new('WWW::Mechanize::FormFiller::Value::Test'); my $f = WWW::Mechanize::FormFiller->new( default => [ 'Test' ] ); isa_ok($f,"WWW::Mechanize::FormFiller"); my $form = HTML::Form->parse(<
HTML $f->fill_form($form); my ($method,$args) = $value->next_call; is($method,undef,"Image inputs don't get called if they are not explicitly specified"); my $filled_input = $form->find_input("image1"); is($filled_input->value, 'Original Value', "Returned image values stay what they are set to") }; }; WWW-Mechanize-FormFiller-0.13/t/04-FF-api.t0000755000175000017500000001205713040205704017343 0ustar corioncorionuse strict; use Test::More tests => 33; use_ok("WWW::Mechanize::FormFiller"); my $f = WWW::Mechanize::FormFiller->new(); isa_ok($f,"WWW::Mechanize::FormFiller"); # Now check our published API : my $meth; for $meth (qw(add_filler add_value fill_form fillout )) { can_ok($f,$meth); }; $f = WWW::Mechanize::FormFiller->new( default => [ Fixed => "foo" ]); isa_ok($f,"WWW::Mechanize::FormFiller"); isa_ok($f->{default},"WWW::Mechanize::FormFiller::Value::Fixed","Default value"); $f = WWW::Mechanize::FormFiller->new( default => [Default => "foo"], values => [[ foo => Fixed => "foo"], [ bar => Default => "bar"], [ baz => Random => "1","2","3" ], ]); isa_ok($f,"WWW::Mechanize::FormFiller"); isa_ok($f->{default},"WWW::Mechanize::FormFiller::Value::Default","Default value"); is(scalar keys %{$f->{values}->{byname}}, 3, "Correct number of values gets stored"); $f = WWW::Mechanize::FormFiller->new(values => [[ login => Fixed => "root" ]]); my $v = WWW::Mechanize::FormFiller::Value::Fixed->new(undef,"secret"); $f->add_value(password => $v); $f->add_value(password_confirm => $v); isa_ok($f,"WWW::Mechanize::FormFiller"); is($f->{default},undef,"Passing in no default results in no default being set"); is(scalar keys %{$f->{values}->{byname}}, 3, "Correct number of values gets stored"); is($f->{values}->{byname}->{password}, $f->{values}->{byname}->{password_confirm}, "Duplicate values get stored only once"); my $croaked; { local *Carp::croak = sub {$croaked .= $_[0]}; $f = WWW::Mechanize::FormFiller->new(values => "don't know"); isnt($croaked,undef,"We croaked on invalid parameters"); like($croaked,qr"values parameter must be an array reference","Passing no array reference as values raises an error"); undef $croaked; }; { local *Carp::croak = sub {$croaked .= $_[0]}; $f = WWW::Mechanize::FormFiller->new(values => ["don't know"]); isnt($croaked,undef,"We croaked on invalid parameters"); like($croaked,qr"Each element of the values array must be an array reference","Passing no array reference as element of values raises an error"); undef $croaked; }; { local *Carp::croak = sub {$croaked .= $_[0]}; $f = WWW::Mechanize::FormFiller->new(values => [["don't know"]]); isnt($croaked,undef,"We croaked on invalid parameters"); like($croaked,qr"Each element of the values array must have at least 2 elements \(name and class\)","Passing too few array elements raises an error"); undef $croaked; }; { local *Carp::croak = sub {$croaked .= $_[0]}; $f = WWW::Mechanize::FormFiller->new(values => [[undef,""]]); isnt($croaked,undef,"We croaked on invalid parameters"); like($croaked,qr"Each element of the values array must have a class name","Passing an empty classname raises an error"); undef $croaked; }; { local *Carp::croak = sub {$croaked .= $_[0]}; $f = WWW::Mechanize::FormFiller->new(); $f->add_filler( foo => "" => "bar" ); isnt($croaked,undef,"add_filler croaks on invalid parameters"); like($croaked,qr"A value must have at least a class name and a field name \(which may be undef though\)","Passing an empty classname to add_filler raises an error"); undef $croaked; }; SKIP: { eval { require HTML::Form; }; skip "Need HTML::Form to test fillout()", 2 if $@; my $form = HTML::Form->parse('
','http://www.example.com'); { local *Carp::croak = sub { die @_}; eval { $f = WWW::Mechanize::FormFiller->fillout($form,$form); }; $croaked = $@; isnt($croaked,undef,"fillout croaks on double form"); like($croaked,qr"Two HTML::Form objects passed into fillout\(\)","Passing two forms to fillout raises an error"); undef $croaked; }; }; SKIP: { eval { require HTML::Form; }; skip "Need HTML::Form to test fillout()", 2 if $@; my $form = HTML::Form->parse('
','http://www.example.com'); $f = WWW::Mechanize::FormFiller->fillout($form, name => 'Mark' ); isa_ok($f,'WWW::Mechanize::FormFiller'); is($form->value('name'),'Mark','fillout has a default of Fixed'); }; SKIP: { eval { require HTML::Form; }; skip "Need HTML::Form to test fillout()", 2 if $@; my $form = HTML::Form->parse('
','http://www.example.com'); $f = WWW::Mechanize::FormFiller->fillout($form, name => [ Random => 'Mark' ]); isa_ok($f,'WWW::Mechanize::FormFiller'); is($form->value('name'),'Mark','Other classes work as well'); }; SKIP: { eval { require HTML::Form; }; skip "Need HTML::Form to test fillout()", 2 if $@; my $form = HTML::Form->parse('
','http://www.example.com'); $f = WWW::Mechanize::FormFiller->fillout(name => [ Random => 'Mark' ], $form); isa_ok($f,'WWW::Mechanize::FormFiller'); is($form->value('name'),'Mark','The place of $form is irrelevant'); }; WWW-Mechanize-FormFiller-0.13/t/01-FF-Value-Fixed.t0000755000175000017500000000073113040205704020674 0ustar corioncorionuse strict; my @values; BEGIN { @values = ("foo",1,"",0,undef); }; use Test::More tests => 1 + scalar @values * 3; use_ok("WWW::Mechanize::FormFiller::Value::Fixed"); for my $value (@values) { my $v = WWW::Mechanize::FormFiller::Value::Fixed->new("foo",$value); isa_ok($v,"WWW::Mechanize::FormFiller::Value::Fixed"); can_ok($v,"value"); my $pvalue = $value ||""; is($v->value(undef),$value,"Fixed returns the correct value for $pvalue"); };WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Random.t0000644000175000017500000000752213040205704026521 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Random.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random eval { require WWW::Mechanize::FormFiller::Value::Random }; skip "Need module WWW::Mechanize::FormFiller::Value::Random to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 40 lib/WWW/Mechanize/FormFiller/Value/Random.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random->new( login => "root","administrator","corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random => "foo","bar","baz" ); ; } }; is($@, '', "example from line 40"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random eval { require WWW::Mechanize::FormFiller::Value::Random }; skip "Need module WWW::Mechanize::FormFiller::Value::Random to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 40 lib/WWW/Mechanize/FormFiller/Value/Random.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random->new( login => "root","administrator","corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random => "foo","bar","baz" ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^(root|administrator|corion)$/, "Login gets set"); like( $form->value('password'), qr/^(foo|bar|baz)$/, "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value.t0000644000175000017500000000227113040205704025277 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 34 lib/WWW/Mechanize/FormFiller/Value.pm # This class is not used directly ; } }; is($@, '', "example from line 34"); }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/00-FF-Value.t0000755000175000017500000000065213040205704017640 0ustar corioncorionuse strict; use Test::More tests => 5; use_ok("WWW::Mechanize::FormFiller::Value"); # Check the API : my $v = WWW::Mechanize::FormFiller::Value->new("foo"); # Now check our published API : my $meth; for $meth (qw(name value)) { can_ok($v,$meth); }; # name is a read-only property : is( $v->name, "foo", "The name was set correctly" ); $v->name("bar"); is( $v->name, "bar", "The name can be changed" ); WWW-Mechanize-FormFiller-0.13/t/07-FF-Value-Random.t0000755000175000017500000000161513040205704021065 0ustar corioncorionuse strict; use Test::More tests => 1 + 3 + 3; use_ok("WWW::Mechanize::FormFiller::Value::Random"); SKIP: { eval { require Test::MockObject }; skip "Need Test::MockObject to do tests on values", 3+3 if $@; my @values = ("foo","bar","baz"); my $value; my $input = Test::MockObject->new()->set_always('value',$value); my $v = WWW::Mechanize::FormFiller::Value::Random->new("foo","bar"); isa_ok($v,"WWW::Mechanize::FormFiller::Value::Random"); can_ok($v,"value"); is($v->value($input),"bar","Single argument list returns single argument"); $input = Test::MockObject->new()->set_always('value',$value); $v = WWW::Mechanize::FormFiller::Value::Random->new("foo",@values); isa_ok($v,"WWW::Mechanize::FormFiller::Value::Random"); can_ok($v,"value"); like($v->value($input),"/" . join("|",@values)."/","Multiple arguments return one of the list"); };WWW-Mechanize-FormFiller-0.13/t/03-FF-Value-Callback.t0000755000175000017500000000221613040205704021333 0ustar corioncorionuse strict; my @values; BEGIN { @values = ("foo","bar","","baz",1,0); }; use Test::More tests => 1 + scalar @values * 7; use_ok("WWW::Mechanize::FormFiller::Value::Callback"); SKIP: { eval { require Test::MockObject }; skip "Need Test::MockObject to do tests on values", scalar @values *7 if $@; my $called; my $value; my $return_value; sub callback { my ($ff_value,$form_value) = @_; isa_ok($ff_value,"WWW::Mechanize::FormFiller::Value::Callback"); $called = 1; can_ok($form_value, "value"); is($form_value->value,$value,"Value passed correctly to callback ($value)"); $return_value; }; my $val; for $val (@values) { $value = $val; undef $called; $return_value = $value; my $input = Test::MockObject->new()->set_always('value',$value); my $v = WWW::Mechanize::FormFiller::Value::Callback->new("foo",\&callback); isa_ok($v,"WWW::Mechanize::FormFiller::Value::Callback"); can_ok($v,"value"); is($v->value($input),$return_value,"Callback returns the correct value for ('$value')"); is($called,1,"Callback was called for ($value)"); }; };WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Callback.t0000644000175000017500000001023213040205704026765 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Callback.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Callback eval { require WWW::Mechanize::FormFiller::Value::Callback }; skip "Need module WWW::Mechanize::FormFiller::Value::Callback to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 34 lib/WWW/Mechanize/FormFiller/Value/Callback.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Callback; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put the current login name into the login field sub find_login { getlogin || getpwuid($<) || "Kilroy"; }; my $login = WWW::Mechanize::FormFiller::Value::Callback->new( login => \&find_login ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put a nice number there my $password = $f->add_filler( password => Callback => sub { int rand(90) + 10 } ); ; } }; is($@, '', "example from line 34"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Callback eval { require WWW::Mechanize::FormFiller::Value::Callback }; skip "Need module WWW::Mechanize::FormFiller::Value::Callback to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 34 lib/WWW/Mechanize/FormFiller/Value/Callback.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Callback; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put the current login name into the login field sub find_login { getlogin || getpwuid($<) || "Kilroy"; }; my $login = WWW::Mechanize::FormFiller::Value::Callback->new( login => \&find_login ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put a nice number there my $password = $f->add_filler( password => Callback => sub { int rand(90) + 10 } ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); my $login_str = getlogin || getpwuid($<) || "Kilroy"; is( $form->value('login'), $login_str, "Login gets set"); cmp_ok( $form->value('password'), '<', 100, "Password gets set"); cmp_ok( $form->value('password'), '>', 9, "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Random-Word.t0000644000175000017500000001040313040205704027422 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Random/Word.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Word eval { require WWW::Mechanize::FormFiller::Value::Random::Word }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Word to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 32 lib/WWW/Mechanize/FormFiller/Value/Random/Word.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Word; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Word->new( login => size => 1 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random::Word => size => 1 ); # Spew some bogus text into the comments field my $comments = $f->add_filler( comments => Random::Word => size => 10 ); ; } }; is($@, '', "example from line 32"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Word eval { require WWW::Mechanize::FormFiller::Value::Random::Word }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Word to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 32 lib/WWW/Mechanize/FormFiller/Value/Random/Word.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Word; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Word->new( login => size => 1 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random::Word => size => 1 ); # Spew some bogus text into the comments field my $comments = $f->add_filler( comments => Random::Word => size => 10 ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^(\w+)$/, "Login gets set"); like( $form->value('password'), qr/^(\w+)$/, "Password gets set"); my @words = split(" ", $form->value('comments')); is( scalar @words, 10, "Comments get set") or diag "Words found : ",$form->value('comments'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Interactive.t0000644000175000017500000000744413040205704027561 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Interactive.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Interactive eval { require WWW::Mechanize::FormFiller::Value::Interactive }; skip "Need module WWW::Mechanize::FormFiller::Value::Interactive to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 36 lib/WWW/Mechanize/FormFiller/Value/Interactive.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Interactive; my $f = WWW::Mechanize::FormFiller->new(); # Ask the user for the "login" my $login = WWW::Mechanize::FormFiller::Value::Interactive->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "Ask the user for the password" my $password = $f->add_filler( password => 'Interactive' ); ; } }; is($@, '', "example from line 36"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Interactive eval { require WWW::Mechanize::FormFiller::Value::Interactive }; skip "Need module WWW::Mechanize::FormFiller::Value::Interactive to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 36 lib/WWW/Mechanize/FormFiller/Value/Interactive.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Interactive; my $f = WWW::Mechanize::FormFiller->new(); # Ask the user for the "login" my $login = WWW::Mechanize::FormFiller::Value::Interactive->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "Ask the user for the password" my $password = $f->add_filler( password => 'Interactive' ); require HTML::Form; BEGIN { no warnings 'redefine'; *WWW::Mechanize::FormFiller::Value::Interactive::ask_value = sub {'fixed'}}; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "fixed", "Login gets set"); is( $form->value('password'), "fixed", "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/02-FF-Value-Default.t0000755000175000017500000000215613040205704021225 0ustar corioncorionuse strict; my @values; BEGIN { @values = ( ["foo","","foo"], [1,"",1], ["","",""], [0,"",0], [undef,"",undef], ["foo","foo","foo"], [1,"foo","foo"], ["","foo","foo"], [0,"foo","foo"], [undef,"foo","foo"], ["foo",1,1], [1,1,1], ["",1,1], [0,1,1], [undef,1,1], ["foo",0,0], [1,0,0], ["",0,0], [0,0,0], [undef,0,0], ); }; use Test::More tests => 1 + scalar @values * 3; use_ok("WWW::Mechanize::FormFiller::Value::Default"); SKIP: { eval { require Test::MockObject }; skip "Need Test::MockObject to do tests on values", scalar @values *3 if $@; for my $row (@values) { my ($value,$form_value,$expected) = @$row; my $input = Test::MockObject->new()->set_always('value',$form_value); my $v = WWW::Mechanize::FormFiller::Value::Default->new("foo",$value); isa_ok($v,"WWW::Mechanize::FormFiller::Value::Default"); can_ok($v,"value"); my $pvalue = $value || ""; is($v->value($input),$expected,"Fixed returns the correct value for ('$pvalue'/'$form_value')"); }; };WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Random-Chars.t0000644000175000017500000000766413040205704027566 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Random/Chars.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Chars eval { require WWW::Mechanize::FormFiller::Value::Random::Chars }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Chars to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 33 lib/WWW/Mechanize/FormFiller/Value/Random/Chars.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Chars; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Chars->new( login => set => 'alpha', min => 3, max => 8 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => 'Random::Chars' ); ; } }; is($@, '', "example from line 33"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Random::Chars eval { require WWW::Mechanize::FormFiller::Value::Random::Chars }; skip "Need module WWW::Mechanize::FormFiller::Value::Random::Chars to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 33 lib/WWW/Mechanize/FormFiller/Value/Random/Chars.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Chars; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Chars->new( login => set => 'alpha', min => 3, max => 8 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => 'Random::Chars' ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^([a-zA-Z]+)$/, "Login gets set"); like( $form->value('password'), qr/^([a-zA-Z]+)$/, "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Keep.t0000644000175000017500000000701013040205704026155 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Keep.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Keep eval { require WWW::Mechanize::FormFiller::Value::Keep }; skip "Need module WWW::Mechanize::FormFiller::Value::Keep to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 28 lib/WWW/Mechanize/FormFiller/Value/Keep.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Keep; my $f = WWW::Mechanize::FormFiller->new(); # Leave the login field untouched my $login = WWW::Mechanize::FormFiller::Value::Keep->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $sessionid = $f->add_filler( session => 'Keep' ); ; } }; is($@, '', "example from line 28"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Keep eval { require WWW::Mechanize::FormFiller::Value::Keep }; skip "Need module WWW::Mechanize::FormFiller::Value::Keep to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 28 lib/WWW/Mechanize/FormFiller/Value/Keep.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Keep; my $f = WWW::Mechanize::FormFiller->new(); # Leave the login field untouched my $login = WWW::Mechanize::FormFiller::Value::Keep->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $sessionid = $f->add_filler( session => 'Keep' ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "foo", "Login gets set"); is( $form->value('sessionid'), "bar", "Password gets set"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller-Value-Default.t0000644000175000017500000001041513040205704026660 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller/Value/Default.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Default eval { require WWW::Mechanize::FormFiller::Value::Default }; skip "Need module WWW::Mechanize::FormFiller::Value::Default to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 32 lib/WWW/Mechanize/FormFiller/Value/Default.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Default; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put "Corion" into the login field unless # there already is some other text. my $login = WWW::Mechanize::FormFiller::Value::Default->new( login => "Corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put 'secret' there" my $password = $f->add_filler( password => Default => "secret" ); ; } }; is($@, '', "example from line 32"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Default eval { require WWW::Mechanize::FormFiller::Value::Default }; skip "Need module WWW::Mechanize::FormFiller::Value::Default to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 32 lib/WWW/Mechanize/FormFiller/Value/Default.pm use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Default; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put "Corion" into the login field unless # there already is some other text. my $login = WWW::Mechanize::FormFiller::Value::Default->new( login => "Corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put 'secret' there" my $password = $f->add_filler( password => Default => "secret" ); require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Corion", "Login gets set"); is( $form->value('password'), "secret", "Password gets set"); $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Test", "Login gets not overwritten"); is( $form->value('password'), "geheim", "Password gets not overwritten"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/t/embedded-WWW-Mechanize-FormFiller.t0000644000175000017500000004115114276737404024250 0ustar corioncorion#!/opt/perl58/bin/perl -w use Test::More 'no_plan'; package Catch; sub TIEHANDLE { my($class, $var) = @_; return bless { var => $var }, $class; } sub PRINT { my($self) = shift; ${'main::'.$self->{var}} .= join '', @_; } sub OPEN {} # XXX Hackery in case the user redirects sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. sub READ {} sub READLINE {} sub GETC {} sub BINMODE {} my $Original_File = 'lib/WWW/Mechanize/FormFiller.pm'; package main; # pre-5.8.0's warns aren't caught by a tied STDERR. $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; }; tie *STDOUT, 'Catch', '_STDOUT_' or die $!; tie *STDERR, 'Catch', '_STDERR_' or die $!; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 161 lib/WWW/Mechanize/FormFiller.pm use WWW::Mechanize::FormFiller; use HTML::Form; # Create a form filler that fills out google for my homepage my $html = "
"; my $f = WWW::Mechanize::FormFiller->new( values => [ [q => Fixed => "Corion Homepage"], ]); my $form = HTML::Form->parse($html,"http://www.google.com/intl/en/"); $f->fill_form($form); my $request = $form->click("btnG"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; ; } }; is($@, '', "example from line 161"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 161 lib/WWW/Mechanize/FormFiller.pm use WWW::Mechanize::FormFiller; use HTML::Form; # Create a form filler that fills out google for my homepage my $html = "
"; my $f = WWW::Mechanize::FormFiller->new( values => [ [q => Fixed => "Corion Homepage"], ]); my $form = HTML::Form->parse($html,"http://www.google.com/intl/en/"); $f->fill_form($form); my $request = $form->click("btnG"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; $_STDOUT_ =~ s/[\x0a\x0d]+$//; is($_STDOUT_,"GET http://www.google.com/search?q=Corion+Homepage&btnG=Google+Search&secretValue=0xDEADBEEF",'Got the expected HTTP query string'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 197 lib/WWW/Mechanize/FormFiller.pm use WWW::Mechanize::FormFiller; use HTML::Form; my $html = "
"; my $f = WWW::Mechanize::FormFiller->new( values => [ [date_birth => Fixed => "01.01.1970"], # We are less discriminate with the other dates [qr/date_birth/ => 'Random::Date' => string => '%d.%m.%Y'], ]); my $form = HTML::Form->parse($html,"http://www.example.com"); $f->fill_form($form); my $request = $form->click("fool"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; ; } }; is($@, '', "example from line 197"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller eval { require WWW::Mechanize::FormFiller }; skip "Need module WWW::Mechanize::FormFiller to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 197 lib/WWW/Mechanize/FormFiller.pm use WWW::Mechanize::FormFiller; use HTML::Form; my $html = "
"; my $f = WWW::Mechanize::FormFiller->new( values => [ [date_birth => Fixed => "01.01.1970"], # We are less discriminate with the other dates [qr/date_birth/ => 'Random::Date' => string => '%d.%m.%Y'], ]); my $form = HTML::Form->parse($html,"http://www.example.com"); $f->fill_form($form); my $request = $form->click("fool"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; $_STDOUT_ =~ s/[\x0a\x0d]+$//; like($_STDOUT_,qr"^GET\shttp://www\.example\.com/ \?date_birth_spouse=\d\d.\d\d.\d\d\d\d \&date_birth=01.01.1970 \&date_birth_kid_1=\d\d.\d\d.\d\d\d\d \&date_birth_kid_2=\d\d.\d\d.\d\d\d\d (?:\&fool=)?$"x,'Got the expected HTTP query string'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Interactive eval { require WWW::Mechanize::FormFiller::Value::Interactive }; skip "Need module WWW::Mechanize::FormFiller::Value::Interactive to run this test", 1 if $@; # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 240 lib/WWW/Mechanize/FormFiller.pm no warnings 'once'; require HTML::Form; require WWW::Mechanize::FormFiller::Value::Interactive; local *WWW::Mechanize::FormFiller::Value::Interactive::ask_value = sub { "s3[r3t" }; #<-- not a good password # Create a form filler that asks us for the password # Normally, the HTML would come from a LWP::UserAgent request my $html = "
"; my $f = WWW::Mechanize::FormFiller->new(); my $form = HTML::Form->parse($html,"http://www.fbi.gov/super/secret/"); $f->add_filler( password => Interactive => []); $f->fill_form($form); my $request = $form->click("Login"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; ; } }; is($@, '', "example from line 240"); }; SKIP: { # A header testing whether we find all prerequisites : # Check for module HTML::Form eval { require HTML::Form }; skip "Need module HTML::Form to run this test", 1 if $@; # Check for module WWW::Mechanize::FormFiller::Value::Interactive eval { require WWW::Mechanize::FormFiller::Value::Interactive }; skip "Need module WWW::Mechanize::FormFiller::Value::Interactive to run this test", 1 if $@; # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 240 lib/WWW/Mechanize/FormFiller.pm no warnings 'once'; require HTML::Form; require WWW::Mechanize::FormFiller::Value::Interactive; local *WWW::Mechanize::FormFiller::Value::Interactive::ask_value = sub { "s3[r3t" }; #<-- not a good password # Create a form filler that asks us for the password # Normally, the HTML would come from a LWP::UserAgent request my $html = "
"; my $f = WWW::Mechanize::FormFiller->new(); my $form = HTML::Form->parse($html,"http://www.fbi.gov/super/secret/"); $f->add_filler( password => Interactive => []); $f->fill_form($form); my $request = $form->click("Login"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; isa_ok($f,"WWW::Mechanize::FormFiller"); $_STDOUT_ =~ s/[\x0a\x0d]+$//; like($_STDOUT_,qr"^GET http://www.fbi.gov/login.asp\?login=&(password=.*?&)?Login=Log\+in&session=0xDEADBEEF",'Got the expected HTTP query string'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 301 lib/WWW/Mechanize/FormFiller.pm # This filler fills all unspecified fields # with the string "" my $f = WWW::Mechanize::FormFiller->new( default => [ Fixed => "" ]); # This filler automatically fills in a username # and asks for a password my $f = WWW::Mechanize::FormFiller->new( values => [[ login => Fixed => "corion" ], [ password => Interactive => []], ]); # This filler only fills in a username # if it is the empty string, and still asks for the password : my $f = WWW::Mechanize::FormFiller->new( values => [[ login => Default => "corion" ], [ password => Interactive => [], ]]); ; } }; is($@, '', "example from line 301"); }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 351 lib/WWW/Mechanize/FormFiller.pm $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # For the the simple case, assumed 'Fixed' class, name => 'Mark', # With an array reference, create and fill with the right kind of object. widget_id => [ 'Random', (1..5) ], ); ; } }; is($@, '', "example from line 351"); }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 351 lib/WWW/Mechanize/FormFiller.pm $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # For the the simple case, assumed 'Fixed' class, name => 'Mark', # With an array reference, create and fill with the right kind of object. widget_id => [ 'Random', (1..5) ], ); isa_ok($filler,"WWW::Mechanize::FormFiller"); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 367 lib/WWW/Mechanize/FormFiller.pm $form = HTML::Form->parse('
','http://www.example.com/'); $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # If the first parameter isa HTML::Form, it is # filled out directly $form, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); ; } }; is($@, '', "example from line 367"); }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 367 lib/WWW/Mechanize/FormFiller.pm $form = HTML::Form->parse('
','http://www.example.com/'); $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # If the first parameter isa HTML::Form, it is # filled out directly $form, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); isa_ok($filler,"WWW::Mechanize::FormFiller"); is($form->value('name'),'Mark','Name is set'); like($form->value('motto'),qr/^[-'\w]+( [-'\w]+){3} [-'\w]+$/,'Motto is set'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; eval q{ my $example = sub { local $^W = 0; #line 391 lib/WWW/Mechanize/FormFiller.pm $form2 = HTML::Form->parse('
','http://www.example.com/'); # This works as a direct constructor as well WWW::Mechanize::FormFiller->fillout( $form2, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); ; } }; is($@, '', "example from line 391"); }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test { undef $main::_STDOUT_; undef $main::_STDERR_; #line 391 lib/WWW/Mechanize/FormFiller.pm $form2 = HTML::Form->parse(' ','http://www.example.com/'); # This works as a direct constructor as well WWW::Mechanize::FormFiller->fillout( $form2, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); isa_ok($filler,"WWW::Mechanize::FormFiller"); is($form2->value('name'),'Mark','Name is set'); like($form->value('motto'),qr/^[-'\w]+( [-'\w]+){3} [-'\w]+$/,'Motto is set'); undef $main::_STDOUT_; undef $main::_STDERR_; } }; SKIP: { # A header testing whether we find all prerequisites : # The original POD test undef $main::_STDOUT_; undef $main::_STDERR_; }; WWW-Mechanize-FormFiller-0.13/.gitignore0000755000175000017500000000022713040205704017414 0ustar corioncorionblib Makefile WWW-Mechanize-FormFiller-* *.old *.bak *.tar.gz *.tar pm_to_blib pm_to_blib.ts .lwpcookies .releaserc META.yml MYMETA.* blibdirs.ts inc/ WWW-Mechanize-FormFiller-0.13/META.yml0000644000175000017500000000117314276737724016723 0ustar corioncorion--- abstract: 'framework to automate HTML forms' author: - 'Max Maischein ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: WWW-Mechanize-FormFiller no_index: directory: - t - inc requires: Data::Random: '0.05' HTML::Form: '0' HTML::Tagset: '0' Test::More: '0' version: '0.13' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' WWW-Mechanize-FormFiller-0.13/lib/0000755000175000017500000000000014276737724016216 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/0000755000175000017500000000000014276737724016702 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/0000755000175000017500000000000014276737724020605 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller.pm0000644000175000017500000003246214276737646023216 0ustar corioncorionpackage WWW::Mechanize::FormFiller; use strict; use Carp; use vars qw( $VERSION @ISA ); $VERSION = '0.13'; @ISA = (); sub load_value_class { my ($class) = @_; if ($class) { no strict 'refs'; my $full_class = "WWW::Mechanize::FormFiller::Value::$class"; unless (defined eval '${' . $full_class . '::VERSION}') { eval "use $full_class"; Carp::confess $@ if $@; }; } else { Carp::croak "No class name given to load" unless $class; }; }; sub new { my ($class,%args) = @_; my $self = { values => {}, default => undef }; bless $self, $class; if (exists $args{default}) { my ($class,@args) = @{$args{default}}; load_value_class($class); no strict 'refs'; $self->{default} = "WWW::Mechanize::FormFiller::Value::$class"->new(undef, @args); }; if (exists $args{values}) { if (ref $args{values} eq 'ARRAY') { for my $value (@{$args{values}}) { if (ref $value eq 'ARRAY') { my ($name,$class,@args) = @$value; if ($class) { $self->add_filler( $name, $class, @args ); } else { Carp::croak "Each element of the values array must have at least 2 elements (name and class)" unless defined $class; Carp::croak "Each element of the values array must have a class name" unless $class; }; } else { Carp::croak "Each element of the values array must be an array reference"; }; } } else { Carp::croak "values parameter must be an array reference"; }; }; return $self; }; sub add_filler { my ($self,$name,$class,@args) = @_; load_value_class($class); if ($class) { no strict 'refs'; $self->add_value( $name, "WWW::Mechanize::FormFiller::Value::$class"->new($name, @args)); } else { Carp::croak "A value must have at least a class name and a field name (which may be undef though)" ; }; }; sub add_value { my ($self, $name, $value) = @_; if (ref $name and UNIVERSAL::isa($name,'Regexp')) { $self->{values}->{byre}->{$name} = $value; } else { $self->{values}->{byname}->{$name} = $value; }; $value; }; sub default { my ($self,$newdefault) = @_; my $result = $self->{default}; $self->{default} = $newdefault if (@_ > 1); $result; }; sub find_filler { my ($self,$input) = @_; croak "No input given" unless defined $input; my $value; if (exists $self->{values}->{byname}->{$input->name()}) { $value = $self->{values}->{byname}->{$input->name}; } elsif (grep { $input->name =~ /$_/ } keys %{$self->{values}->{byre}}) { my $match = (grep { $input->name =~ /$_/ } keys %{$self->{values}->{byre}})[0]; $value = $self->{values}->{byre}->{$match}; } elsif ($input->type eq "image") { # Image inputs are really buttons, and if they have no (user) specified value, # we don't ask about them. } elsif ($self->default) { $value = $self->default(); }; $value; }; sub fill_form { my ($self,$form) = @_; for my $input ($form->inputs) { my $value = $self->find_filler($input); # We leave all values alone whenever we don't know what to do with them if (defined $value) { # Hmm - who cares about whether a value was hidden/readonly ?? no warnings; local $^W = undef; my $v = $value->value($input); undef $v if ($input->type() eq "checkbox" and $v eq ""); eval { $input->value( $v ) }; $@ and croak "Field '" .$input->name. "' had illegal value: $v"; }; }; }; sub fillout { my $self_class = shift; my $self = ref $self_class ? $self_class : $self_class->new(); my $form; while (@_) { if (ref $_[0] and eval { UNIVERSAL::isa($_[0],'HTML::Form') }) { croak "Two HTML::Form objects passed into fillout()" if ($form); $form = shift; } else { my $field = shift; if (ref $_[0] eq 'ARRAY') { my $args = shift; $self->add_filler($field,@$args); } else { my $value = shift; $self->add_filler($field,'Fixed',$value); }; }; }; $self->fill_form($form) if $form; $self; }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller - framework to automate HTML forms =head1 SYNOPSIS =begin example use WWW::Mechanize::FormFiller; use HTML::Form; # Create a form filler that fills out google for my homepage my $html = " "; my $f = WWW::Mechanize::FormFiller->new( values => [ [q => Fixed => "Corion Homepage"], ]); my $form = HTML::Form->parse($html,"http://www.google.com/intl/en/"); $f->fill_form($form); my $request = $form->click("btnG"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; =end example =for example_testing $_STDOUT_ =~ s/[\x0a\x0d]+$//; is($_STDOUT_,"GET http://www.google.com/search?q=Corion+Homepage&btnG=Google+Search&secretValue=0xDEADBEEF",'Got the expected HTTP query string'); Form fields can be specified by name or by a regular expression. A field specified by name takes precedence over a matching regular expression. =for example use WWW::Mechanize::FormFiller; use HTML::Form; =begin example my $html = "
"; my $f = WWW::Mechanize::FormFiller->new( values => [ [date_birth => Fixed => "01.01.1970"], # We are less discriminate with the other dates [qr/date_birth/ => 'Random::Date' => string => '%d.%m.%Y'], ]); my $form = HTML::Form->parse($html,"http://www.example.com"); $f->fill_form($form); my $request = $form->click("fool"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; =end example =for example_testing $_STDOUT_ =~ s/[\x0a\x0d]+$//; like($_STDOUT_,qr"^GET\shttp://www\.example\.com/ \?date_birth_spouse=\d\d.\d\d.\d\d\d\d \&date_birth=01.01.1970 \&date_birth_kid_1=\d\d.\d\d.\d\d\d\d \&date_birth_kid_2=\d\d.\d\d.\d\d\d\d" (?:\&fool=)?$"x,'Got the expected HTTP query string'); You are not limited to fixed form values - callbacks and interactive editing are also already provided : =for example no warnings 'once'; require HTML::Form; require WWW::Mechanize::FormFiller::Value::Interactive; local *WWW::Mechanize::FormFiller::Value::Interactive::ask_value = sub { "s3[r3t" }; #<-- not a good password =for example begin # Create a form filler that asks us for the password # Normally, the HTML would come from a LWP::UserAgent request my $html = "
"; my $f = WWW::Mechanize::FormFiller->new(); my $form = HTML::Form->parse($html,"http://www.fbi.gov/super/secret/"); $f->add_filler( password => Interactive => []); $f->fill_form($form); my $request = $form->click("Login"); # Now we have a complete HTTP request, which we can hand off to # LWP::UserAgent or (preferrably) WWW::Mechanize print $request->as_string; =for example end =for example_testing isa_ok($f,"WWW::Mechanize::FormFiller"); $_STDOUT_ =~ s/[\x0a\x0d]+$//; like($_STDOUT_,qr"^GET http://www.fbi.gov/login.asp\?login=&(password=.*?&)?Login=Log\+in&session=0xDEADBEEF",'Got the expected HTTP query string'); =head1 DESCRIPTION The module is intended as a simple way to fill out HTML forms from a set of predetermined values. You set up the form filler with value elements, retrieve the HTML form, and let the form filler loose on that form. There are value classes provided for many tasks - fixed values, values to be queried interactively from the user, values taken randomly from a list of values and values specified through a callback to some Perl code. =over 4 =item new %ARGS Creates a new instance. The C<%ARGS> hash has two possible keys : C, whose value should be an array reference consisting of the name of a C subclass and the optional constructor values. C must be an array reference, which contains array and C, which takes an array reference to the filenames to watch. Example : =begin example # This filler fills all unspecified fields # with the string "" my $f = WWW::Mechanize::FormFiller->new( default => [ Fixed => "" ]); # This filler automatically fills in a username # and asks for a password my $f = WWW::Mechanize::FormFiller->new( values => [[ login => Fixed => "corion" ], [ password => Interactive => []], ]); # This filler only fills in a username # if it is the empty string, and still asks for the password : my $f = WWW::Mechanize::FormFiller->new( values => [[ login => Default => "corion" ], [ password => Interactive => [], ]]); =end example =item add_filler NAME, CLASS, @ARGS Adds a new value to the list of filled fields. C is the name of the form field, C is the name of the class in the C namespace - it must live below there ! C<@ARGS> is an optional array reference to the parameters that the subclass constructor takes. =item add_value NAME, VALUE Adds a new WWW::Mechanize::FormFiller::Value subclass to the list of filled fields. C is the name of the form field, C is an object that responds to the interface of C. =item fill_form FORM Sets the field values in FORM to the values returned by the C elements. FORM should be of type HTML::Forms or respond to the same interface. =item fillout @ARGS This is a very dwimmy routine that allows you to intuitively set up values and fill out a form, if needed. It works as both a constructor and a method. The parameters are decoded according to the following examples : =for example begin $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # For the the simple case, assumed 'Fixed' class, name => 'Mark', # With an array reference, create and fill with the right kind of object. widget_id => [ 'Random', (1..5) ], ); =for example end =for example_testing isa_ok($filler,"WWW::Mechanize::FormFiller"); =for example $form = HTML::Form->parse('
','http://www.example.com/'); =for example begin $filler = WWW::Mechanize::FormFiller->new(); $filler->fillout( # If the first parameter isa HTML::Form, it is # filled out directly $form, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); =for example end =for example_testing isa_ok($filler,"WWW::Mechanize::FormFiller"); is($form->value('name'),'Mark','Name is set'); like($form->value('motto'),qr/^[-'\w]+( [-'\w]+){3} [-'\w]+$/,'Motto is set'); =for example $form2 = HTML::Form->parse('
','http://www.example.com/'); =for example begin # This works as a direct constructor as well WWW::Mechanize::FormFiller->fillout( $form2, name => 'Mark', motto => [ 'Random::Word', size => 5 ], ); =for example end =for example_testing isa_ok($filler,"WWW::Mechanize::FormFiller"); is($form2->value('name'),'Mark','Name is set'); like($form->value('motto'),qr/^[-'\w]+( [-'\w]+){3} [-'\w]+$/,'Motto is set'); =back =head2 Value subclasses The following WWW::Mechanize::FormFiller::Value subclasses are currently distributed : =over 4 =item L =item L =item L =item L =item L =item L =item L =item L =item L =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! Bug reports are best done via RT at https://rt.cpan.org =head1 SEE ALSO L,L,L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/0000755000175000017500000000000014276737724022646 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/0000755000175000017500000000000014276737724023722 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Keep.pm0000644000175000017500000000440314276737646025150 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Keep; use base 'WWW::Mechanize::FormFiller::Value'; use strict; use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name,$value) = @_; my $self = $class->SUPER::new($name); $self->{value} = $value; $self; }; sub value { $_[1]->value }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Keep - Leave an HTML field alone =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Keep; my $f = WWW::Mechanize::FormFiller->new(); # Leave the login field untouched my $login = WWW::Mechanize::FormFiller::Value::Keep->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $sessionid = $f->add_filler( session => 'Keep' ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse(' ','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "foo", "Login gets set"); is( $form->value('sessionid'), "bar", "Password gets set"); =head1 DESCRIPTION This class provides a way to keep a value in an HTML field. =over 4 =item new NAME Creates a new value which will correspond to the HTML field C. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns whatever Cvalue()> returns. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L,L, L,L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Callback.pm0000644000175000017500000000563314276737646025766 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Callback; use base 'WWW::Mechanize::FormFiller::Value'; use strict; use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name,$coderef) = @_; my $self = $class->SUPER::new($name); $self->{callback} = $coderef; $self; }; sub value { my ($self,$input) = @_; no strict 'refs'; $self->{callback}->($self,$input); }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Callback - Call Perl code to fill out a HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Callback; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put the current login name into the login field sub find_login { getlogin || getpwuid($<) || "Kilroy"; }; my $login = WWW::Mechanize::FormFiller::Value::Callback->new( login => \&find_login ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put a nice number there my $password = $f->add_filler( password => Callback => sub { int rand(90) + 10 } ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); my $login_str = getlogin || getpwuid($<) || "Kilroy"; is( $form->value('login'), $login_str, "Login gets set"); cmp_ok( $form->value('password'), '<', 100, "Password gets set"); cmp_ok( $form->value('password'), '>', 9, "Password gets set"); =head1 DESCRIPTION This class provides a way to write a value returned by Perl code into a HTML field. =over 4 =item new NAME, CODE Creates a new value which will correspond to the HTML field C. The C is a code reference that will return the value to be written into the HTML field. The code reference will be called with two parameters, the object and the HTML::Form::Input object. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Fixed.pm0000644000175000017500000000455314276737646025331 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Fixed; use base 'WWW::Mechanize::FormFiller::Value'; use strict; use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name,$value) = @_; my $self = $class->SUPER::new($name); $self->{value} = $value; $self; }; sub value { $_[0]->{value} }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Fixed - Fill a fixed value into an HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Fixed; my $f = WWW::Mechanize::FormFiller->new(); # Create a fixed value for the HTML field "login" my $fixed = WWW::Mechanize::FormFiller::Value::Fixed->new( login => "Corion" ); $f->add_value( login => $fixed ); # Alternatively take the following shorthand, which adds the # field to the list as well : my $password = $f->add_filler( password => Fixed => "secret" ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Corion", "Login gets set"); is( $form->value('password'), "secret", "Password gets set"); =head1 DESCRIPTION This class provides a way to write a fixed value into a HTML field. =over 4 =item new NAME, VALUE Creates a new value which will correspond to the HTML field C. The C is the value to be written into the HTML field. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Interactive.pm0000644000175000017500000000550714276737646026547 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Interactive; use base 'WWW::Mechanize::FormFiller::Value::Callback'; use strict; use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name) = @_; my $self = $class->SUPER::new($name, \&ask_value); $self; }; sub ask_value { my ($self,$input) = @_; print $input->name,"> ","[",$input->value,"]"; my $result = <>; chomp $result; $result = $input->value if $result eq ""; $result; }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Interactive - Ask the user to fill out a HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Interactive; my $f = WWW::Mechanize::FormFiller->new(); # Ask the user for the "login" my $login = WWW::Mechanize::FormFiller::Value::Interactive->new( 'login' ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "Ask the user for the password" my $password = $f->add_filler( password => 'Interactive' ); =for example end =for example_testing require HTML::Form; BEGIN { no warnings 'redefine'; *WWW::Mechanize::FormFiller::Value::Interactive::ask_value = sub {'fixed'}}; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "fixed", "Login gets set"); is( $form->value('password'), "fixed", "Password gets set"); =head1 DESCRIPTION This class provides a way to write a value read from STDIN into a HTML field. =over 4 =item new NAME Creates a new value which will correspond to the HTML field C. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. The value will be read from STDIN. The name of the HTML field to be read and the current value will be printed to STDOUT. An empty string will use the given default. There currently is no way to enter an empty string if there is a different default string. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Default.pm0000644000175000017500000000572414276737646025657 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Default; use base 'WWW::Mechanize::FormFiller::Value'; use strict; use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name,$value) = @_; my $self = $class->SUPER::new($name); $self->{value} = $value; $self; }; sub value { my ($self,$input) = @_; defined $input->value && $input->value ne "" ? $input->value : $self->{value}; }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Default - Fill a fixed value into an empty HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Default; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put "Corion" into the login field unless # there already is some other text. my $login = WWW::Mechanize::FormFiller::Value::Default->new( login => "Corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put 'secret' there" my $password = $f->add_filler( password => Default => "secret" ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Corion", "Login gets set"); is( $form->value('password'), "secret", "Password gets set"); $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); is( $form->value('login'), "Test", "Login gets not overwritten"); is( $form->value('password'), "geheim", "Password gets not overwritten"); =head1 DESCRIPTION This class provides a way to write a fixed value into a HTML field. =over 4 =item new NAME, VALUE Creates a new value which will correspond to the HTML field C. The C is the value to be written into the HTML field. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Random.pm0000644000175000017500000000574614276737646025517 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Random; use strict; use base 'WWW::Mechanize::FormFiller::Value'; use Data::Random qw(rand_enum); use vars qw( $VERSION ); $VERSION = '0.13'; sub new { my ($class,$name,@values) = @_; my $self = $class->SUPER::new($name); $self->{values} = [ @values ]; $self; }; sub value { my ($self,$input) = @_; my @values; @values = @{$self->{values}} if ($self->{values}); # Pick a choice among the allowed values for this input # unless we got some prespecified values @values = $input->possible_values unless scalar @values; rand_enum( set => \@values, size => 1 ); }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Random - Randomly fill out a HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random->new( login => "root","administrator","corion" ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random => "foo","bar","baz" ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^(root|administrator|corion)$/, "Login gets set"); like( $form->value('password'), qr/^(foo|bar|baz)$/, "Password gets set"); =head1 DESCRIPTION This class provides a way to write a randomly chosen value into a HTML field. =over 4 =item new NAME, LIST Creates a new value which will correspond to the HTML field C. The C is a list of items one of which will be returned for each call to C. There is no persistence of these values. For items that can only take a finite set of elements, a random element out of that list is taken by default. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Random/0000755000175000017500000000000014276737724025142 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Random/Date.pm0000644000175000017500000000735414276737646026371 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Random::Date; use base 'WWW::Mechanize::FormFiller::Value'; use Carp qw(croak); use vars qw( $VERSION ); use POSIX; $VERSION = '0.13'; sub new { my ($class,$name,%args) = @_; my $self = $class->SUPER::new($name); %args = (string => '%Y%m%d') unless scalar (keys %args); $args{min} ||= undef; $args{max} ||= undef; $self->{args} = \%args; $self; }; sub value { my ($self,$input) = @_; my $min = $self->{args}->{min}; my $max = $self->{args}->{max}; for ($min, $max) { $_ = strftime $self->{args}->{string}, gmtime() if $_ eq "now"; }; croak "Minimum timestamp is greater or equal maximum timestamp" if defined $max and defined $min and $max le $min; my $result; RANDOM: { my $timestamp = rand(0x7FFFFFFF); #warn $self->{args}->{string}; #warn gmtime($timestamp); $result = strftime $self->{args}->{string}, gmtime($timestamp); redo RANDOM if defined $min and $result lt $min; redo RANDOM if defined $max and $result ge $max; }; $result; }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Random::Date - Fill a timestamp into an HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Date; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "born" my $born = WWW::Mechanize::FormFiller::Value::Random::Date->new( born => string => '%Y%m%d', min => '20000101', max => '20373112' ); $f->add_value( born => $born ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $last_here = $f->add_filler( last_here => Random::Date => string => '%H%M%S', min => '000000', max => 'now'); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('born'), qr/^(\d{8})$/, "born gets set"); like( $form->value('last_here'), qr/^(\d{6})$/, "last_here gets set"); =head1 DESCRIPTION This class provides a way to write a randomly chosen value into a HTML field. =over 4 =item new NAME, %ARGS Creates a new value which will correspond to the HTML field C. The allowed %ARGS are string => POSIX strftime string min => minimum time stamp (inclusive) max => maximum time stamp (exclusive) The C and C time stamps must be in the same format as the C supplies. B The algorithm to implement C and C barriers is very simplicistic - it tries as many random values as necessary to meet the two criteria. This means that your script may enter an infinite loop if the criteria can never be attained or are too little apart. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Random/Chars.pm0000644000175000017500000000541714276737646026552 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Random::Chars; use base 'WWW::Mechanize::FormFiller::Value'; use strict; use vars qw( $VERSION ); use Data::Random qw(rand_chars); $VERSION = '0.13'; sub new { my ($class,$name,@args) = @_; my $self = $class->SUPER::new($name); @args = (set => 'alpha', min => 5, max => 8) unless scalar @args; $self->{args} = [ @args ]; $self; }; sub value { my ($self,$input) = @_; join "", (rand_chars( @{$self->{args}} )); }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Random::Chars - Fill characters into an HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Chars; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Chars->new( login => set => 'alpha', min => 3, max => 8 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => 'Random::Chars' ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^([a-zA-Z]+)$/, "Login gets set"); like( $form->value('password'), qr/^([a-zA-Z]+)$/, "Password gets set"); =head1 DESCRIPTION This class provides a way to write a randomly chosen value into a HTML field. =over 4 =item new NAME, LIST Creates a new value which will correspond to the HTML field C. The C is the list of arguments passed to Data::Random::rand_chars. If the list is empty, C<< set => 'alpha', min => 5, max => 8 >> is assumed. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value/Random/Word.pm0000644000175000017500000000573014276737646026423 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value::Random::Word; use base 'WWW::Mechanize::FormFiller::Value'; use vars qw( $VERSION ); use Data::Random qw(rand_words); $VERSION = '0.13'; sub new { my ($class,$name,@args) = @_; my $self = $class->SUPER::new($name); @args = (size => 1) unless scalar @args; $self->{args} = [ @args ]; $self; }; sub value { my ($self,$input) = @_; return join " ", @{rand_words( @{$self->{args}} )}; }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value::Random::Word - Fill a word into an HTML form field =head1 SYNOPSIS =for example begin use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Random::Word; my $f = WWW::Mechanize::FormFiller->new(); # Create a random value for the HTML field "login" my $login = WWW::Mechanize::FormFiller::Value::Random::Word->new( login => size => 1 ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # If there is no password, put a random one out of the list there my $password = $f->add_filler( password => Random::Word => size => 1 ); # Spew some bogus text into the comments field my $comments = $f->add_filler( comments => Random::Word => size => 10 ); =for example end =for example_testing require HTML::Form; my $form = HTML::Form->parse('
','http://www.example.com/'); $f->fill_form($form); like( $form->value('login'), qr/^(\w+)$/, "Login gets set"); like( $form->value('password'), qr/^(\w+)$/, "Password gets set"); my @words = split(" ", $form->value('comments')); is( scalar @words, 10, "Comments get set") or diag "Words found : ",$form->value('comments'); =head1 DESCRIPTION This class provides a way to write a randomly chosen value into a HTML field. =over 4 =item new NAME, LIST Creates a new value which will correspond to the HTML field C. The C is the list of arguments passed to Data::Random::rand_words. If the list is empty, C<< size => 1 >> is assumed. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L, L, L, L, L, L, L, L WWW-Mechanize-FormFiller-0.13/lib/WWW/Mechanize/FormFiller/Value.pm0000644000175000017500000000312714276737646024266 0ustar corioncorionpackage WWW::Mechanize::FormFiller::Value; use vars qw( $VERSION @ISA ); $VERSION = '0.13'; @ISA = (); sub new { my ($class,$name) = @_; my $self = { name => $name, }; bless $self,$class; $self; }; # You're supposed to override this sub value { undef }; # You can't set the name, but retrieve it sub name { my $result = $_[0]->{name}; $_[0]->{name} = $_[1] if scalar @_ == 2; $result }; 1; __END__ =head1 NAME WWW::Mechanize::FormFiller::Value - Base class for HTML form values =head1 SYNOPSIS =begin example # This class is not used directly =end example =head1 DESCRIPTION This class is the base class for different values - it defines the interface implemented by the subclasses. =over 4 =item new NAME Creates a new value which will correspond to the HTML field C. =item name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. =item value FIELD Returns the value to put into the HTML field. =back =head2 EXPORT None by default. =head2 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! =head1 SEE ALSO L,L,L,L, L,L,L WWW-Mechanize-FormFiller-0.13/META.json0000644000175000017500000000203114276737724017065 0ustar corioncorion{ "abstract" : "framework to automate HTML forms", "author" : [ "Max Maischein " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "WWW-Mechanize-FormFiller", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Data::Random" : "0.05", "HTML::Form" : "0", "HTML::Tagset" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.13", "x_serialization_backend" : "JSON::PP version 4.11" } WWW-Mechanize-FormFiller-0.13/xt/0000755000175000017500000000000014276737724016103 5ustar corioncorionWWW-Mechanize-FormFiller-0.13/xt/99-todo.t0000644000175000017500000000202713040205704017445 0ustar corioncorionuse Test::More; use File::Spec; use File::Find; use strict; # Check that all files do not contain any # lines with "XXX" - such markers should # either have been converted into Todo-stuff # or have been resolved. # The test was provided by Andy Lester. my @files; my $blib = File::Spec->catfile(qw(blib lib)); find(\&wanted, grep { -d } ($blib, 'bin')); plan tests => 2* @files; foreach my $file (@files) { source_file_ok($file); } sub wanted { push @files, $File::Find::name if /\.p(l|m|od)$/; } sub source_file_ok { my $file = shift; open( my $fh, "<$file" ) or die "Can't open $file: $!"; my @lines = <$fh>; close $fh; my $n = 0; for ( @lines ) { ++$n; s/^/$file ($n): /; } my @x = grep /XXX/, @lines; if ( !is( scalar @x, 0, "Looking for XXXes in $file" ) ) { diag( $_ ) for @x; } @x = grep /<<<|>>>/, @lines; if ( !is( scalar @x, 0, "Looking for <<<<|>>>> in $file" ) ) { diag( $_ ) for @x; } } WWW-Mechanize-FormFiller-0.13/xt/99-changes.t0000644000175000017500000000130213040205704020103 0ustar corioncorion#!perl -w use warnings; use strict; use File::Find; use Test::More tests => 2; =head1 PURPOSE This test ensures that the Changes file mentions the current version and that a release date is mentioned as well =cut my $module = 'WWW::Mechanize::FormFiller'; (my $file = $module) =~ s!::!/!g; require "$file.pm"; my $version = sprintf '%0.2f', $module->VERSION; diag "Checking for version " . $version; my $changes = do { local $/; open my $fh, 'Changes' or die $!; <$fh> }; ok $changes =~ /^(.*$version.*)$/m, "We find version $version"; my $changes_line = $1; ok $changes_line =~ /$version\s+20\d{6}/, "We find a release date on the same line" or diag $changes_line; WWW-Mechanize-FormFiller-0.13/xt/99-manifest.t0000644000175000017500000000154613040205704020313 0ustar corioncorionuse strict; use Test::More; # Check that MANIFEST and MANIFEST.skip are sane : use File::Find; use File::Spec; my @files = qw( MANIFEST MANIFEST.SKIP ); plan tests => scalar @files * 4 +1 # MANIFEST existence check ; for my $file (@files) { ok(-f $file, "$file exists"); open F, "<$file" or die "Couldn't open $file : $!"; my @lines = ; is_deeply([grep(/^$/, @lines)],[], "No empty lines in $file"); is_deeply([grep(/^\s+$/, @lines)],[], "No whitespace-only lines in $file"); is_deeply([grep(/^\s*\S\s+$/, @lines)],[],"No trailing whitespace on lines in $file"); if ($file eq 'MANIFEST') { chomp @lines; is_deeply([grep { s/\s.*//; ! -f } @lines], [], "All files in $file exist") or do { diag "$_ is mentioned in $file but doesn't exist on disk" for grep { ! -f } @lines }; }; close F; }; WWW-Mechanize-FormFiller-0.13/xt/99-unix-text.t0000644000175000017500000000140413040205704020443 0ustar corioncorionuse Test::More; # Check that all released module files are in # UNIX text format use File::Spec; use File::Find; use strict; my @files; my $blib = File::Spec->catfile(qw(blib lib)); find(\&wanted, grep { -d } ($blib, 'bin')); plan tests => scalar @files; foreach my $file (@files) { unix_file_ok($file); } sub wanted { push @files, $File::Find::name if /\.p(l|m|od)$/; } sub unix_file_ok { my ($filename) = @_; local $/; open F, "< $filename" or die "Couldn't open '$filename' : $!\n"; binmode F; my $content = ; my $i; my @lines = grep { /\x0D\x0A$/sm } map { sprintf "%s: %s\x0A", $i++, $_ } split /\x0A/, $content; unless (is(scalar @lines, 0,"'$filename' contains no windows newlines")) { diag $_ for @lines; }; close F; }; WWW-Mechanize-FormFiller-0.13/xt/99-pod.t0000644000175000017500000000123213040205704017257 0ustar corioncorionuse Test::More; # Check our Pod # The test was provided by Andy Lester, # who stole it from Brian D. Foy # Thanks to both ! use File::Spec; use File::Find; use strict; eval { require Test::Pod; Test::Pod->import; }; my @files; if ($@) { plan skip_all => "Test::Pod required for testing POD"; } elsif ($Test::Pod::VERSION < 0.95) { plan skip_all => "Test::Pod 0.95 required for testing POD"; } else { my $blib = File::Spec->catfile(qw(blib lib)); find(\&wanted, grep { -d } ($blib, 'bin')); plan tests => scalar @files; foreach my $file (@files) { pod_file_ok($file); } } sub wanted { push @files, $File::Find::name if /\.p(l|m|od)$/; } WWW-Mechanize-FormFiller-0.13/xt/99-compile.t0000644000175000017500000000137713040205704020137 0ustar corioncorion#!perl -w use warnings; use strict; use File::Find; use Test::More; BEGIN { eval 'use Capture::Tiny ":all"; 1'; if ($@) { plan skip_all => "Capture::Tiny needed for testing"; exit 0; }; }; plan 'no_plan'; my $last_version = undef; sub check { return if (! m{(\.pm|\.pl) \z}xmsi); my ($stdout, $stderr, $exit) = capture(sub { system( $^X, '-Mblib', '-wc', $_ ); }); s!\s*\z!! for ($stdout, $stderr); if( $exit ) { diag $exit; fail($_); } elsif( $stderr ne "$_ syntax OK") { diag $stderr; fail($_); } else { pass($_); }; } find({wanted => \&check, no_chdir => 1}, grep { -d $_ } 'blib', 'scripts', 'examples', 'bin', 'lib' ); WWW-Mechanize-FormFiller-0.13/xt/99-versions.t0000644000175000017500000000242213040205704020347 0ustar corioncorion#!perl -w # Stolen from ChrisDolan on use.perl.org # http://use.perl.org/comments.pl?sid=29264&cid=44309 use warnings; use strict; use File::Find; use Test::More; BEGIN { eval 'use File::Slurp; 1'; if ($@) { plan skip_all => "File::Slurp needed for testing"; exit 0; }; }; plan 'no_plan'; my $last_version = undef; sub check { return if (! m{blib/script/}xms && ! m{\.pm \z}xms); my $content = read_file($_); # only look at perl scripts, not sh scripts return if (m{blib/script/}xms && $content !~ m/\A \#![^\r\n]+?perl/xms); my @version_lines = $content =~ m/ ( [^\n]* \$VERSION \s* = [^=] [^\n]* ) /gxms; if (@version_lines == 0) { fail($_); } for my $line (@version_lines) { $line =~ s/^\s+//; $line =~ s/\s+$//; if (!defined $last_version) { $last_version = shift @version_lines; diag "Checking for $last_version"; pass($_); } else { is($line, $last_version, $_); } } } find({wanted => \&check, no_chdir => 1}, 'blib'); if (! defined $last_version) { fail('Failed to find any files with $VERSION'); } WWW-Mechanize-FormFiller-0.13/Changes0000755000175000017500000000411114276737526016743 0ustar corioncorionRevision history for Perl extension WWW::Mechanize::FormFiller. 0.13 20220816 . Address changes in HTML::Form 6.08 Thanks to Julien and Slaven for alerting me to this change! 0.12 20170119 . Prerequisite fix, no need to update - Data::Tagset was not listed as an installation prerequisite 0.11 20140119 . Test fix, no need to update - Data::Random returns words containing ' or - ; adjust tests for that Thanks to Slaven Rezic for reporting this as RT #91944 0.10 20090424 . Distribution fix, no need to update - added MANIFEST.skip to distribution - POD formatting fix thanks to Damyan Ivanov 0.09 20090418 . Test fix, no need to update - Finally remove t/08*, which checked for HTML::Form behaviour which changed - Update author test suite 0.08 20071009 - Rerelease because the old one went missing - No need to upgrade 0.07 20071007 - Rerelease because the old one went missing - No need to upgrade 0.06 20061214 - Added patch (plus Test) by Mark Stosberg to make filling in an invalid value to a field die with a more descriptive message - Disabled automatic inline test generation 0.05 ???????? - Documentation fixed for Chars.pm (Thanks to Mark Stosberg) - Now it is possible to also use regular expressions instead of names to specify the fields. - Added documentation and inline test for the above feature 0.04 20030517 - Fixed Makefile.PL for Perl 5.8.0 - Fixed inline tests - Fixed inline examples so they actually show in the Pod - Added more inline tests to test the synopses - New prerequisite: Data::Random - to fill out forms with better random data - Added custom random date generation - Added 'use strict' to all FormFiller::Value::* modules (only cosmetic) - Added WWW::Mechanize::FormFiller::fillout, the dwim routine to fill out forms, suggested by Mark Stosberg. Thanks ! 0.02 20030217 - More tests - Inline tests - first release on CPAN in preparation of WWW::Mechanize::Shell 0.01 Thu Nov 7 23:04:33 2002 - original version; created by h2xs 1.21 with options -X WWW::Mechanize::FormFiller WWW-Mechanize-FormFiller-0.13/README0000644000175000017500000000150614276737646016335 0ustar corioncorionWWW/Mechanize/FormFiller version 0.13 ===================================== WWW::Mechanize::FormFiller and its submodules are useful to automate web forms. The FormFiller object is filled with a set of rules how to fill out HTML form field and then let loose on a HTML form. It fills in the fields according to the preset rules. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Test::More for the tests HTML::Form for the filling of HTML forms HTML::Tagset See Makefile.PL for a complete list of the prerequisites. COPYRIGHT AND LICENCE These modules may be used under the same terms as Perl itself Copyright (C) 2002,2017 Max Maischein, corion@cpan.org WWW-Mechanize-FormFiller-0.13/cvstest0000644000175000017500000000021013040205704017027 0ustar corioncorion#!/bin/bash perl Makefile.PL 2>&1 make test 2>&1 perl5.8.0 Makefile.PL 2>&1 make test 2>&1 perl5.6.1 Makefile.PL 2>&1 make test 2>&1 WWW-Mechanize-FormFiller-0.13/MANIFEST0000644000175000017500000000263713040205704016561 0ustar corioncorion.gitignore Changes cvstest lib/WWW/Mechanize/FormFiller.pm lib/WWW/Mechanize/FormFiller/Value.pm lib/WWW/Mechanize/FormFiller/Value/Callback.pm lib/WWW/Mechanize/FormFiller/Value/Default.pm lib/WWW/Mechanize/FormFiller/Value/Fixed.pm lib/WWW/Mechanize/FormFiller/Value/Interactive.pm lib/WWW/Mechanize/FormFiller/Value/Keep.pm lib/WWW/Mechanize/FormFiller/Value/Random.pm lib/WWW/Mechanize/FormFiller/Value/Random/Chars.pm lib/WWW/Mechanize/FormFiller/Value/Random/Date.pm lib/WWW/Mechanize/FormFiller/Value/Random/Word.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.json META.yml README t/00-FF-Value.t t/01-FF-Value-Fixed.t t/02-FF-Value-Default.t t/03-FF-Value-Callback.t t/04-FF-api.t t/05-Form-1.t t/06-Form-Image-Button.t t/07-FF-Value-Random.t t/embedded-WWW-Mechanize-FormFiller-Value-Callback.t t/embedded-WWW-Mechanize-FormFiller-Value-Default.t t/embedded-WWW-Mechanize-FormFiller-Value-Fixed.t t/embedded-WWW-Mechanize-FormFiller-Value-Interactive.t t/embedded-WWW-Mechanize-FormFiller-Value-Keep.t t/embedded-WWW-Mechanize-FormFiller-Value-Random-Chars.t t/embedded-WWW-Mechanize-FormFiller-Value-Random-Date.t t/embedded-WWW-Mechanize-FormFiller-Value-Random-Word.t t/embedded-WWW-Mechanize-FormFiller-Value-Random.t t/embedded-WWW-Mechanize-FormFiller-Value.t t/embedded-WWW-Mechanize-FormFiller.t xt/99-changes.t xt/99-compile.t xt/99-manifest.t xt/99-pod.t xt/99-todo.t xt/99-unix-text.t xt/99-versions.t