From 3e29d833e4fbe59c83e7ae52a7413b193c1083bd Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Mon, 24 Mar 2008 18:50:29 +0000 Subject: [PATCH] Imported Upstream version 0.13 --- Changes | 3 + META.yml | 10 +- Makefile.PL | 9 +- inc/Module/Install.pm | 2 +- inc/Module/Install/AutoInstall.pm | 2 +- inc/Module/Install/Base.pm | 2 +- inc/Module/Install/Can.pm | 2 +- inc/Module/Install/Fetch.pm | 2 +- inc/Module/Install/Include.pm | 2 +- inc/Module/Install/Makefile.pm | 331 ++++++++++++++++++++------------------ inc/Module/Install/Metadata.pm | 47 ++++-- inc/Module/Install/Win32.pm | 2 +- inc/Module/Install/WriteAll.pm | 2 +- lib/WWW/OpenSearch.pm | 32 ++-- lib/WWW/OpenSearch/Agent.pm | 4 +- lib/WWW/OpenSearch/Description.pm | 96 +++++++---- lib/WWW/OpenSearch/Request.pm | 8 +- lib/WWW/OpenSearch/Response.pm | 81 +++++----- lib/WWW/OpenSearch/Url.pm | 22 +-- t/01_live.t | 15 +- t/10-description.t | 76 +++++---- t/11-url.t | 61 +++++-- t/13-request.t | 6 +- t/98_pod.t | 8 +- t/99_pod_coverage.t | 9 +- 25 files changed, 480 insertions(+), 354 deletions(-) diff --git a/Changes b/Changes index 101c634..d14ce4c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension WWW::OpenSearch +0.13 Fri Dec 21 2007 + - Fix pod coverage (Ian Beckwith) + 0.12 Tue May 01 2007 - switch from ||= to a "defined" idiom for some params - switch to Module::Install diff --git a/META.yml b/META.yml index 5bd1bc4..701f1bf 100644 --- a/META.yml +++ b/META.yml @@ -1,8 +1,11 @@ --- abstract: Search A9 OpenSearch compatible engines -author: Brian Cassidy +author: + - Brian Cassidy +build_requires: + Test::More: 0 distribution_type: module -generated_by: Module::Install version 0.65 +generated_by: Module::Install version 0.68 license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html @@ -16,9 +19,8 @@ requires: Data::Page: 2 Encode: 0 LWP: 5.6 - Test::More: 0 URI: 0 URI::Template: 0 XML::Feed: 0.08 XML::LibXML: 1.58 -version: 0.12 +version: 0.13 diff --git a/Makefile.PL b/Makefile.PL index 903ee78..167bf65 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,4 +1,8 @@ -use inc::Module::Install 0.65; +use inc::Module::Install 0.68; + +if ( -e 'MANIFEST.SKIP' ) { + system( 'pod2text lib/WWW/OpenSearch.pm > README' ); +} name 'WWW-OpenSearch'; all_from 'lib/WWW/OpenSearch.pm'; @@ -10,7 +14,8 @@ requires 'XML::LibXML' => 1.58; requires 'Encode'; requires 'URI'; requires 'URI::Template'; -requires 'Test::More'; + +test_requires 'Test::More'; auto_install; WriteAll; diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm index af6a59c..89a8653 100644 --- a/inc/Module/Install.pm +++ b/inc/Module/Install.pm @@ -28,7 +28,7 @@ BEGIN { # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. - $VERSION = '0.65'; + $VERSION = '0.68'; } # Whether or not inc::Module::Install is actually loaded, the diff --git a/inc/Module/Install/AutoInstall.pm b/inc/Module/Install/AutoInstall.pm index b4b55af..3a490fb 100644 --- a/inc/Module/Install/AutoInstall.pm +++ b/inc/Module/Install/AutoInstall.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm index b46a8ca..49dfde6 100644 --- a/inc/Module/Install/Base.pm +++ b/inc/Module/Install/Base.pm @@ -1,7 +1,7 @@ #line 1 package Module::Install::Base; -$VERSION = '0.65'; +$VERSION = '0.68'; # Suspend handler for "redefined" warnings BEGIN { diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm index 9bcf278..ec66fdb 100644 --- a/inc/Module/Install/Can.pm +++ b/inc/Module/Install/Can.pm @@ -11,7 +11,7 @@ use ExtUtils::MakeMaker (); use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm index 0d2c39c..e0dd6db 100644 --- a/inc/Module/Install/Fetch.pm +++ b/inc/Module/Install/Fetch.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/inc/Module/Install/Include.pm b/inc/Module/Install/Include.pm index 964b93d..001d0c6 100644 --- a/inc/Module/Install/Include.pm +++ b/inc/Module/Install/Include.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm index eb67033..17bd8a7 100644 --- a/inc/Module/Install/Makefile.pm +++ b/inc/Module/Install/Makefile.pm @@ -7,7 +7,7 @@ use ExtUtils::MakeMaker (); use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } @@ -17,196 +17,221 @@ sub Makefile { $_[0] } my %seen = (); sub prompt { - shift; - - # Infinite loop protection - my @c = caller(); - if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { - die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; - } - - # In automated testing, always use defaults - if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) { - local $ENV{PERL_MM_USE_DEFAULT} = 1; - goto &ExtUtils::MakeMaker::prompt; - } else { - goto &ExtUtils::MakeMaker::prompt; - } + shift; + + # Infinite loop protection + my @c = caller(); + if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { + die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; + } + + # In automated testing, always use defaults + if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) { + local $ENV{PERL_MM_USE_DEFAULT} = 1; + goto &ExtUtils::MakeMaker::prompt; + } else { + goto &ExtUtils::MakeMaker::prompt; + } } sub makemaker_args { - my $self = shift; - my $args = ($self->{makemaker_args} ||= {}); - %$args = ( %$args, @_ ) if @_; - $args; + my $self = shift; + my $args = ($self->{makemaker_args} ||= {}); + %$args = ( %$args, @_ ) if @_; + $args; } # For mm args that take multiple space-seperated args, # append an argument to the current list. sub makemaker_append { - my $self = shift; - my $name = shift; - my $args = $self->makemaker_args; - $args->{name} = defined $args->{$name} - ? join( ' ', $args->{name}, @_ ) - : join( ' ', @_ ); + my $self = sShift; + my $name = shift; + my $args = $self->makemaker_args; + $args->{name} = defined $args->{$name} + ? join( ' ', $args->{name}, @_ ) + : join( ' ', @_ ); } sub build_subdirs { - my $self = shift; - my $subdirs = $self->makemaker_args->{DIR} ||= []; - for my $subdir (@_) { - push @$subdirs, $subdir; - } + my $self = shift; + my $subdirs = $self->makemaker_args->{DIR} ||= []; + for my $subdir (@_) { + push @$subdirs, $subdir; + } } sub clean_files { - my $self = shift; - my $clean = $self->makemaker_args->{clean} ||= {}; - %$clean = ( - %$clean, - FILES => join(' ', grep length, $clean->{FILES}, @_), - ); + my $self = shift; + my $clean = $self->makemaker_args->{clean} ||= {}; + %$clean = ( + %$clean, + FILES => join(' ', grep length, $clean->{FILES}, @_), + ); } sub realclean_files { - my $self = shift; - my $realclean = $self->makemaker_args->{realclean} ||= {}; - %$realclean = ( - %$realclean, - FILES => join(' ', grep length, $realclean->{FILES}, @_), - ); + my $self = shift; + my $realclean = $self->makemaker_args->{realclean} ||= {}; + %$realclean = ( + %$realclean, + FILES => join(' ', grep length, $realclean->{FILES}, @_), + ); } sub libs { - my $self = shift; - my $libs = ref $_[0] ? shift : [ shift ]; - $self->makemaker_args( LIBS => $libs ); + my $self = shift; + my $libs = ref $_[0] ? shift : [ shift ]; + $self->makemaker_args( LIBS => $libs ); } sub inc { - my $self = shift; - $self->makemaker_args( INC => shift ); + my $self = shift; + $self->makemaker_args( INC => shift ); +} + +my %test_dir = (); + +sub _wanted_t { + /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1; +} + +sub tests_recursive { + my $self = shift; + if ( $self->tests ) { + die "tests_recursive will not work if tests are already defined"; + } + my $dir = shift || 't'; + unless ( -d $dir ) { + die "tests_recursive dir '$dir' does not exist"; + } + require File::Find; + %test_dir = (); + File::Find::find( \&_wanted_t, $dir ); + $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir ); } sub write { - my $self = shift; - die "&Makefile->write() takes no arguments\n" if @_; - - my $args = $self->makemaker_args; - $args->{DISTNAME} = $self->name; - $args->{NAME} = $self->module_name || $self->name || $self->determine_NAME($args); - $args->{VERSION} = $self->version || $self->determine_VERSION($args); - $args->{NAME} =~ s/-/::/g; - if ( $self->tests ) { - $args->{test} = { TESTS => $self->tests }; - } - if ($] >= 5.005) { - $args->{ABSTRACT} = $self->abstract; - $args->{AUTHOR} = $self->author; - } - if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) { - $args->{NO_META} = 1; - } - if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) { - $args->{SIGN} = 1; - } - unless ( $self->is_admin ) { - delete $args->{SIGN}; - } - - # merge both kinds of requires into prereq_pm - my $prereq = ($args->{PREREQ_PM} ||= {}); - %$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_, - ($self->build_requires, $self->requires) ); - - # merge both kinds of requires into prereq_pm - my $subdirs = ($args->{DIR} ||= []); - if ($self->bundles) { - foreach my $bundle (@{ $self->bundles }) { - my ($file, $dir) = @$bundle; - push @$subdirs, $dir if -d $dir; - delete $prereq->{$file}; - } - } - - if ( my $perl_version = $self->perl_version ) { - eval "use $perl_version; 1" - or die "ERROR: perl: Version $] is installed, " - . "but we need version >= $perl_version"; - } - - $args->{INSTALLDIRS} = $self->installdirs; - - my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args; - - my $user_preop = delete $args{dist}->{PREOP}; - if (my $preop = $self->admin->preop($user_preop)) { - $args{dist} = $preop; - } - - my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); - $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); + my $self = shift; + die "&Makefile->write() takes no arguments\n" if @_; + + my $args = $self->makemaker_args; + $args->{DISTNAME} = $self->name; + $args->{NAME} = $self->module_name || $self->name || $self->determine_NAME($args); + $args->{VERSION} = $self->version || $self->determine_VERSION($args); + $args->{NAME} =~ s/-/::/g; + if ( $self->tests ) { + $args->{test} = { TESTS => $self->tests }; + } + if ($] >= 5.005) { + $args->{ABSTRACT} = $self->abstract; + $args->{AUTHOR} = $self->author; + } + if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) { + $args->{NO_META} = 1; + } + if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) { + $args->{SIGN} = 1; + } + unless ( $self->is_admin ) { + delete $args->{SIGN}; + } + + # merge both kinds of requires into prereq_pm + my $prereq = ($args->{PREREQ_PM} ||= {}); + %$prereq = ( %$prereq, + map { @$_ } + map { @$_ } + grep $_, + ($self->build_requires, $self->requires) + ); + + # merge both kinds of requires into prereq_pm + my $subdirs = ($args->{DIR} ||= []); + if ($self->bundles) { + foreach my $bundle (@{ $self->bundles }) { + my ($file, $dir) = @$bundle; + push @$subdirs, $dir if -d $dir; + delete $prereq->{$file}; + } + } + + if ( my $perl_version = $self->perl_version ) { + eval "use $perl_version; 1" + or die "ERROR: perl: Version $] is installed, " + . "but we need version >= $perl_version"; + } + + $args->{INSTALLDIRS} = $self->installdirs; + + my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args; + + my $user_preop = delete $args{dist}->{PREOP}; + if (my $preop = $self->admin->preop($user_preop)) { + $args{dist} = $preop; + } + + my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); + $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { - my $self = shift; - my $makefile_name = shift; - my $top_class = ref($self->_top) || ''; - my $top_version = $self->_top->VERSION || ''; - - my $preamble = $self->preamble - ? "# Preamble by $top_class $top_version\n" - . $self->preamble - : ''; - my $postamble = "# Postamble by $top_class $top_version\n" - . ($self->postamble || ''); - - local *MAKEFILE; - open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; - my $makefile = do { local $/; }; - close MAKEFILE or die $!; - - $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; - $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; - $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; - $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; - $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; - - # Module::Install will never be used to build the Core Perl - # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks - # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist - $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; - #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; - - # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. - $makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g; - - # XXX - This is currently unused; not sure if it breaks other MM-users - # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; - - open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; - print MAKEFILE "$preamble$makefile$postamble" or die $!; - close MAKEFILE or die $!; - - 1; + my $self = shift; + my $makefile_name = shift; + my $top_class = ref($self->_top) || ''; + my $top_version = $self->_top->VERSION || ''; + + my $preamble = $self->preamble + ? "# Preamble by $top_class $top_version\n" + . $self->preamble + : ''; + my $postamble = "# Postamble by $top_class $top_version\n" + . ($self->postamble || ''); + + local *MAKEFILE; + open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; + my $makefile = do { local $/; }; + close MAKEFILE or die $!; + + $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; + $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; + $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; + $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; + $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; + + # Module::Install will never be used to build the Core Perl + # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks + # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist + $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; + #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; + + # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. + $makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g; + + # XXX - This is currently unused; not sure if it breaks other MM-users + # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; + + open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; + print MAKEFILE "$preamble$makefile$postamble" or die $!; + close MAKEFILE or die $!; + + 1; } sub preamble { - my ($self, $text) = @_; - $self->{preamble} = $text . $self->{preamble} if defined $text; - $self->{preamble}; + my ($self, $text) = @_; + $self->{preamble} = $text . $self->{preamble} if defined $text; + $self->{preamble}; } sub postamble { - my ($self, $text) = @_; - $self->{postamble} ||= $self->admin->postamble; - $self->{postamble} .= $text if defined $text; - $self->{postamble} + my ($self, $text) = @_; + $self->{postamble} ||= $self->admin->postamble; + $self->{postamble} .= $text if defined $text; + $self->{postamble} } 1; __END__ -#line 338 +#line 363 diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm index b5658c9..f77d68a 100644 --- a/inc/Module/Install/Metadata.pm +++ b/inc/Module/Install/Metadata.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } @@ -56,14 +56,23 @@ foreach my $key (@tuple_keys) { }; } -sub install_as_core { $_[0]->installdirs('perl') } -sub install_as_cpan { $_[0]->installdirs('site') } -sub install_as_site { $_[0]->installdirs('site') } -sub install_as_vendor { $_[0]->installdirs('vendor') } +# configure_requires is currently a null-op +sub configure_requires { 1 } + +# Aliases for build_requires that will have alternative +# meanings in some future version of META.yml. +sub test_requires { shift->build_requires(@_) } +sub install_requires { shift->build_requires(@_) } + +# Aliases for installdirs options +sub install_as_core { $_[0]->installdirs('perl') } +sub install_as_cpan { $_[0]->installdirs('site') } +sub install_as_site { $_[0]->installdirs('site') } +sub install_as_vendor { $_[0]->installdirs('vendor') } sub sign { my $self = shift; - return $self->{'values'}{'sign'} if defined wantarray and !@_; + return $self->{'values'}{'sign'} if defined wantarray and ! @_; $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 ); return $self; } @@ -296,20 +305,24 @@ sub license_from { { my $license_text = $1; my @phrases = ( - 'under the same (?:terms|license) as perl itself' => 'perl', - 'GNU public license' => 'gpl', - 'GNU lesser public license' => 'gpl', - 'BSD license' => 'bsd', - 'Artistic license' => 'artistic', - 'GPL' => 'gpl', - 'LGPL' => 'lgpl', - 'BSD' => 'bsd', - 'Artistic' => 'artistic', - 'MIT' => 'MIT', + 'under the same (?:terms|license) as perl itself' => 'perl', 1, + 'GNU public license' => 'gpl', 1, + 'GNU lesser public license' => 'gpl', 1, + 'BSD license' => 'bsd', 1, + 'Artistic license' => 'artistic', 1, + 'GPL' => 'gpl', 1, + 'LGPL' => 'lgpl', 1, + 'BSD' => 'bsd', 1, + 'Artistic' => 'artistic', 1, + 'MIT' => 'mit', 1, + 'proprietary' => 'proprietary', 0, ); - while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) { + while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s{\s+}{\\s+}g; if ( $license_text =~ /\b$pattern\b/i ) { + if ( $osi and $license_text =~ /All rights reserved/i ) { + warn "LEGAL WARNING: 'All rights reserved' may invalidate Open Source licenses. Consider removing it."; + } $self->license($license); return 1; } diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm index 42cb653..4f808c7 100644 --- a/inc/Module/Install/Win32.pm +++ b/inc/Module/Install/Win32.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm index d0908fb..078797c 100644 --- a/inc/Module/Install/WriteAll.pm +++ b/inc/Module/Install/WriteAll.pm @@ -6,7 +6,7 @@ use Module::Install::Base; use vars qw{$VERSION $ISCORE @ISA}; BEGIN { - $VERSION = '0.65'; + $VERSION = '0.68'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } diff --git a/lib/WWW/OpenSearch.pm b/lib/WWW/OpenSearch.pm index 375623e..5bc3da3 100644 --- a/lib/WWW/OpenSearch.pm +++ b/lib/WWW/OpenSearch.pm @@ -10,11 +10,11 @@ use WWW::OpenSearch::Agent; use WWW::OpenSearch::Request; use WWW::OpenSearch::Description; -use Encode (); +use Encode (); __PACKAGE__->mk_accessors( qw( description_url agent description ) ); -our $VERSION = '0.12'; +our $VERSION = '0.13'; =head1 NAME @@ -111,42 +111,44 @@ it under the same terms as Perl itself. =cut sub new { - my( $class, $url ) = @_; - + my ( $class, $url ) = @_; + croak( "No OpenSearch Description url provided" ) unless $url; - + my $self = $class->SUPER::new; $self->description_url( $url ); $self->agent( WWW::OpenSearch::Agent->new() ); $self->fetch_description; - + return $self; } sub fetch_description { - my( $self, $url ) = @_; + my ( $self, $url ) = @_; $url ||= $self->description_url; $self->description_url( $url ); my $response = $self->agent->get( $url ); - - unless( $response->is_success ) { + + unless ( $response->is_success ) { croak "Error while fetching $url: " . $response->status_line; } - $self->description( WWW::OpenSearch::Description->new( $response->content ) ); + $self->description( + WWW::OpenSearch::Description->new( $response->content ) ); } sub search { - my( $self, $query, $params, $url ) = @_; + my ( $self, $query, $params, $url ) = @_; - $params ||= { }; + $params ||= {}; $params->{ searchTerms } = $query; - Encode::_utf8_off( $params->{ searchTerms } ); - + Encode::_utf8_off( $params->{ searchTerms } ); + $url ||= $self->description->get_best_url; - return $self->agent->search( WWW::OpenSearch::Request->new( $url, $params ) ); + return $self->agent->search( + WWW::OpenSearch::Request->new( $url, $params ) ); } 1; diff --git a/lib/WWW/OpenSearch/Agent.pm b/lib/WWW/OpenSearch/Agent.pm index bc5bbec..1b95c0a 100644 --- a/lib/WWW/OpenSearch/Agent.pm +++ b/lib/WWW/OpenSearch/Agent.pm @@ -46,7 +46,7 @@ it under the same terms as Perl itself. =cut sub new { - my( $class, @rest ) = @_; + my ( $class, @rest ) = @_; return $class->SUPER::new( agent => join( '/', __PACKAGE__, $WWW::OpenSearch::VERSION ), @rest, @@ -57,7 +57,7 @@ sub new { sub request { my $self = shift; - my $request = shift; ; + my $request = shift; my $response = $self->SUPER::request( $request, @_ ); # allow regular HTTP::Requests to flow through diff --git a/lib/WWW/OpenSearch/Description.pm b/lib/WWW/OpenSearch/Description.pm index 0075e35..8af4bd8 100644 --- a/lib/WWW/OpenSearch/Description.pm +++ b/lib/WWW/OpenSearch/Description.pm @@ -89,6 +89,8 @@ whose type is equal to $type. =head2 AdultContent( ) +=head2 Attribution( ) + =head2 Contact( ) =head2 Description( ) @@ -97,10 +99,16 @@ whose type is equal to $type. =head2 Format( ) +=head2 InputEncoding( ) + =head2 Image( ) +=head2 Language( ) + =head2 LongName( ) +=head2 OutputEncoding( ) + =head2 Query( ) =head2 SampleSearch( ) @@ -132,7 +140,7 @@ it under the same terms as Perl itself. =cut -for( @columns ) { +for ( @columns ) { no strict 'refs'; my $col = lc; *$_ = \&$col; @@ -141,11 +149,11 @@ for( @columns ) { sub new { my $class = shift; my $xml = shift; - - my $self = $class->SUPER::new; - - eval{ $self->load( $xml ); } if $xml; - if( $@ ) { + + my $self = $class->SUPER::new; + + eval { $self->load( $xml ); } if $xml; + if ( $@ ) { croak "Error while parsing Description XML: $@"; } @@ -155,17 +163,18 @@ sub new { sub load { my $self = shift; my $xml = shift; - + my $parser = XML::LibXML->new; my $doc = $parser->parse_string( $xml ); my $element = $doc->documentElement; my $nodename = $element->nodeName; - croak "Node should be OpenSearchDescription: $nodename" if $nodename ne 'OpenSearchDescription'; + croak "Node should be OpenSearchDescription: $nodename" + if $nodename ne 'OpenSearchDescription'; my $ns = $element->getNamespace->value; my $version; - if( $ns eq 'http://a9.com/-/spec/opensearchdescription/1.0/' ) { + if ( $ns eq 'http://a9.com/-/spec/opensearchdescription/1.0/' ) { $self->ns( 'http://a9.com/-/spec/opensearchrss/1.0/' ); $version = '1.0'; } @@ -176,10 +185,18 @@ sub load { $self->version( $version ); for my $column ( @columns ) { - my $node = $doc->documentElement->getChildrenByTagName( $column ) or next; - if( $column eq 'Url' ) { - if( $version eq '1.0' ) { - $self->Url( [ WWW::OpenSearch::Url->new( template => $node->string_value, type => 'application/rss+xml', ns => $self->ns ) ] ); + my $node = $doc->documentElement->getChildrenByTagName( $column ) + or next; + if ( $column eq 'Url' ) { + if ( $version eq '1.0' ) { + $self->Url( + [ WWW::OpenSearch::Url->new( + template => $node->string_value, + type => 'application/rss+xml', + ns => $self->ns + ) + ] + ); next; } @@ -187,43 +204,57 @@ sub load { for my $urlnode ( $node->get_nodelist ) { my $type = $urlnode->getAttributeNode( 'type' )->value; my $url = $urlnode->getAttributeNode( 'template' )->value; - $url =~ s/\?}/}/g; # optional + $url =~ s/\?}/}/g; # optional my $method = $urlnode->getAttributeNode( 'method' ); $method = $method->value if $method; my %params; - for( $urlnode->getChildrenByTagName( 'Param' ) ) { + for ( $urlnode->getChildrenByTagName( 'Param' ) ) { my $param = $_->getAttributeNode( 'name' )->value; my $value = $_->getAttributeNode( 'value' )->value; - $value =~ s/\?}/}/g; # optional + $value =~ s/\?}/}/g; # optional $params{ $param } = $value; } - push @url, WWW::OpenSearch::Url->new( template => $url, type => $type, method => $method, params => \%params, ns => $self->ns ); + push @url, + WWW::OpenSearch::Url->new( + template => $url, + type => $type, + method => $method, + params => \%params, + ns => $self->ns + ); } $self->Url( \@url ); } - elsif( $version eq '1.1' and $column eq 'Query' ) { + elsif ( $version eq '1.1' and $column eq 'Query' ) { my $queries = $self->query || []; for my $node ( $node->get_nodelist ) { - my $query = WWW::OpenSearch::Query->new( { - map { $_ => $node->getAttributeNode( $_ )->value } qw( role searchTerms ) - } ); + my $query = WWW::OpenSearch::Query->new( + { map { $_ => $node->getAttributeNode( $_ )->value } + qw( role searchTerms ) + } + ); push @$queries, $query; } $self->query( $queries ); } - elsif( $version eq '1.1' and $column eq 'Image' ) { + elsif ( $version eq '1.1' and $column eq 'Image' ) { my $images = $self->image || []; for my $node ( $node->get_nodelist ) { - my $image = WWW::OpenSearch::Image->new( { - ( map { my $attr = $node->getAttributeNode( $_ ); $attr ? ($_ => $attr->value) : () } qw( height width type ) ), - url => $node->string_value - } ); + my $image = WWW::OpenSearch::Image->new( + { ( map { + my $attr = $node->getAttributeNode( $_ ); + $attr ? ( $_ => $attr->value ) : () + } qw( height width type ) + ), + url => $node->string_value + } + ); push @$images, $image; } @@ -238,8 +269,9 @@ sub load { sub get_best_url { my $self = shift; - - return $self->get_url_by_type( 'application/atom+xml' ) + + return + $self->get_url_by_type( 'application/atom+xml' ) || $self->get_url_by_type( 'application/rss+xml' ) || $self->get_url_by_type( 'text/xml' ) || $self->url->[ 0 ]; @@ -248,11 +280,11 @@ sub get_best_url { sub get_url_by_type { my $self = shift; my $type = shift; - - for( $self->urls ) { + + for ( $self->urls ) { return $_ if $_->type eq $type; - }; - + } + return; } diff --git a/lib/WWW/OpenSearch/Request.pm b/lib/WWW/OpenSearch/Request.pm index 7c33255..ffe7d1b 100644 --- a/lib/WWW/OpenSearch/Request.pm +++ b/lib/WWW/OpenSearch/Request.pm @@ -53,12 +53,12 @@ it under the same terms as Perl itself. =cut sub new { - my( $class, $os_url, $params ) = @_; + my ( $class, $os_url, $params ) = @_; - my( $uri, $post ) = $os_url->prepare_query( $params ); + my ( $uri, $post ) = $os_url->prepare_query( $params ); my $self; - if( lc $os_url->method eq 'post' ) { + if ( lc $os_url->method eq 'post' ) { $self = HTTP::Request::Common::POST( $uri, $post ); bless $self, $class; } @@ -73,7 +73,7 @@ sub new { } sub clone { - my $self = shift; + my $self = shift; my $clone = bless $self->SUPER::clone, ref( $self ); $clone->opensearch_url( $self->opensearch_url ); diff --git a/lib/WWW/OpenSearch/Response.pm b/lib/WWW/OpenSearch/Response.pm index d0b923c..97efcd0 100644 --- a/lib/WWW/OpenSearch/Response.pm +++ b/lib/WWW/OpenSearch/Response.pm @@ -104,13 +104,13 @@ it under the same terms as Perl itself. sub new { my $class = shift; my $response = shift; - + my $self = bless $response, $class; return $self unless $self->is_success; - + $self->parse_response; - + return $self; } @@ -122,7 +122,7 @@ sub parse_response { return if XML::Feed->errstr; $self->feed( $feed ); - + $self->parse_feed; } @@ -133,43 +133,44 @@ sub parse_feed { my $feed = $self->feed; my $format = $feed->format; my $ns = $self->request->opensearch_url->ns; - + # TODO # adapt these for any number of opensearch elements in # the feed or in each entry - - if( my $atom = $feed->{ atom } ) { + + if ( my $atom = $feed->{ atom } ) { my $total = $atom->get( $ns, 'totalResults' ); my $perpage = $atom->get( $ns, 'itemsPerPage' ); my $start = $atom->get( $ns, 'startIndex' ); - + $pager->total_entries( $total ); $pager->entries_per_page( $perpage ); - $pager->current_page( $start ? ( $start - 1 ) / $perpage + 1 : 0 ) + $pager->current_page( $start ? ( $start - 1 ) / $perpage + 1 : 0 ); } - elsif( my $rss = $feed->{ rss } ) { - if ( my $page = $rss->channel->{ $ns } ) { - $pager->total_entries( $page->{ totalResults } ); + elsif ( my $rss = $feed->{ rss } ) { + if ( my $page = $rss->channel->{ $ns } ) { + $pager->total_entries( $page->{ totalResults } ); $pager->entries_per_page( $page->{ itemsPerPage } ); my $start = $page->{ startIndex }; - $pager->current_page( $start ? ( $start - 1 ) / $page->{ itemsPerPage } + 1 : 0 ) + $pager->current_page( + $start ? ( $start - 1 ) / $page->{ itemsPerPage } + 1 : 0 ); } - } + } $self->pager( $pager ); } sub next_page { - my $self = shift; + my $self = shift; return $self->_get_page( 'next' ); } sub previous_page { - my $self = shift; + my $self = shift; return $self->_get_page( 'previous' ); } sub _get_page { - my( $self, $direction ) = @_; + my ( $self, $direction ) = @_; my $pager = $self->pager; my $pagermethod = "${direction}_page"; my $page = $pager->$pagermethod; @@ -178,39 +179,41 @@ sub _get_page { my $params; my $osu = $self->request->opensearch_url; -# this code is too fragile -- deparse depends on the order of query -# params and the like. best just to use the last query params and -# do the paging from there. -# -# if( lc $osu->method ne 'post' ) { # force query build on POST -# my $link = $self->_get_link( $direction ); -# if( $link ) { -# $params = $osu->deparse( $link ); -# } -# } + # this code is too fragile -- deparse depends on the order of query + # params and the like. best just to use the last query params and + # do the paging from there. + # + # if( lc $osu->method ne 'post' ) { # force query build on POST + # my $link = $self->_get_link( $direction ); + # if( $link ) { + # $params = $osu->deparse( $link ); + # } + # } # rebuild the query - if( !$params ) { + if ( !$params ) { $params = $self->request->opensearch_params; # handle paging via a page # $params->{ startPage } = $page; # handle paging via an index - if( exists $params->{ startIndex } ) { + if ( exists $params->{ startIndex } ) { + # start index is pre-existing - if( $params->{ startIndex } ) { - if( $direction eq 'previous' ) { - $params->{ startIndex } -= $pager->entries_per_page + if ( $params->{ startIndex } ) { + if ( $direction eq 'previous' ) { + $params->{ startIndex } -= $pager->entries_per_page; } else { $params->{ startIndex } += $pager->entries_per_page; } } + # start index did not exist previously else { - if( $direction eq 'previous' ) { - $params->{ startIndex } = 1 + if ( $direction eq 'previous' ) { + $params->{ startIndex } = 1; } else { $params->{ startIndex } = $pager->entries_per_page + 1; @@ -221,19 +224,17 @@ sub _get_page { } my $agent = WWW::OpenSearch::Agent->new; - return $agent->search( WWW::OpenSearch::Request->new( - $osu, $params - ) ); + return $agent->search( WWW::OpenSearch::Request->new( $osu, $params ) ); } sub _get_link { my $self = shift; my $type = shift; my $feed = $self->feed->{ atom }; - + return unless $feed; - - for( $feed->link ) { + + for ( $feed->link ) { return $_->href if $_->rel eq $type; } diff --git a/lib/WWW/OpenSearch/Url.pm b/lib/WWW/OpenSearch/Url.pm index 320c1f4..7c04b82 100644 --- a/lib/WWW/OpenSearch/Url.pm +++ b/lib/WWW/OpenSearch/Url.pm @@ -61,32 +61,32 @@ it under the same terms as Perl itself. =cut sub new { - my( $class, %options ) = @_; - + my ( $class, %options ) = @_; + $options{ method } ||= 'GET'; $options{ template } = URI::Template->new( $options{ template } ); - + my $self = $class->SUPER::new( \%options ); return $self; } sub prepare_query { - my( $self, $params ) = @_; + my ( $self, $params ) = @_; my $tmpl = $self->template; - - for( qw( startIndex startPage ) ) { + + for ( qw( startIndex startPage ) ) { $params->{ $_ } = 1 if !defined $params->{ $_ }; } - $params->{ language } ||= '*'; + $params->{ language } ||= '*'; $params->{ outputEncoding } ||= 'UTF-8'; - $params->{ inputEncoding } ||= 'UTF-8'; - + $params->{ inputEncoding } ||= 'UTF-8'; + # fill the uri template my $url = $tmpl->process( %$params ); # attempt to handle POST - if( $self->method eq 'post' ) { + if ( $self->method eq 'post' ) { my $post = $self->params; for my $key ( keys %$post ) { $post->{ $key } =~ s/{(.+)}/$params->{ $1 } || ''/eg; @@ -94,7 +94,7 @@ sub prepare_query { return $url, [ %$post ]; } - + return $url; } diff --git a/t/01_live.t b/t/01_live.t index aeec5f7..c1a2625 100644 --- a/t/01_live.t +++ b/t/01_live.t @@ -1,9 +1,9 @@ use strict; use Test::More; -my $url = $ENV{OPENSEARCH_URL}; -unless ($url) { - Test::More->import(skip_all => "OPENSEARCH_URL not set"); +my $url = $ENV{ OPENSEARCH_URL }; +unless ( $url ) { + Test::More->import( skip_all => "OPENSEARCH_URL not set" ); exit; } @@ -12,13 +12,14 @@ plan 'no_plan'; use WWW::OpenSearch; -my $engine = WWW::OpenSearch->new($url); +my $engine = WWW::OpenSearch->new( $url ); ok $engine; ok $engine->description->shortname, $engine->description->shortname; -my $res = $engine->search("iPod"); +my $res = $engine->search( "iPod" ); ok $res; ok $res->feed->title, $res->feed->title; -ok $res->feed->link, $res->feed->link; -ok $res->pager->entries_per_page, "items per page " . $res->pager->entries_per_page; +ok $res->feed->link, $res->feed->link; +ok $res->pager->entries_per_page, + "items per page " . $res->pager->entries_per_page; ok $res->pager->total_entries, "total entries " . $res->pager->total_entries; diff --git a/t/10-description.t b/t/10-description.t index 3eacf72..868631c 100644 --- a/t/10-description.t +++ b/t/10-description.t @@ -22,8 +22,9 @@ use_ok( 'WWW::OpenSearch::Description' ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); is( $osd->shortname, 'Web Search', 'shortname' ); ok( !defined $osd->longname, 'longname' ); - is( $osd->description, 'Use Example.com to search the Web.', 'description' ); - is( $osd->tags, 'example web', 'tags' ); + is( $osd->description, 'Use Example.com to search the Web.', + 'description' ); + is( $osd->tags, 'example web', 'tags' ); is( $osd->contact, 'admin@example.com', 'contact' ); # count the urls @@ -68,35 +69,37 @@ use_ok( 'WWW::OpenSearch::Description' ); my $osd = WWW::OpenSearch::Description->new( $description ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); - is( $osd->shortname, 'Web Search', 'shortname' ); - is( $osd->longname, 'Example.com Web Search', 'longname' ); - is( $osd->description, 'Use Example.com to search the Web.', 'description' ); - is( $osd->tags, 'example web', 'tags' ); - is( $osd->contact, 'admin@example.com', 'contact' ); + is( $osd->shortname, 'Web Search', 'shortname' ); + is( $osd->longname, 'Example.com Web Search', 'longname' ); + is( $osd->description, 'Use Example.com to search the Web.', + 'description' ); + is( $osd->tags, 'example web', 'tags' ); + is( $osd->contact, 'admin@example.com', 'contact' ); is( $osd->developer, 'Example.com Development Team', 'developer' ); is( $osd->attribution, ' Search data © 2005, Example.com, Inc., All Rights Reserved - ', 'attribution' ); - is( $osd->inputencoding, 'UTF-8', 'inputencoding' ); - is( $osd->outputencoding, 'UTF-8', 'outputencoding' ); - is( $osd->language, 'en-us', 'language' ); - is( $osd->adultcontent, 'false', 'adultcontent' ); - is( $osd->syndicationright, 'open', 'syndicationright' ); + ', 'attribution' + ); + is( $osd->inputencoding, 'UTF-8', 'inputencoding' ); + is( $osd->outputencoding, 'UTF-8', 'outputencoding' ); + is( $osd->language, 'en-us', 'language' ); + is( $osd->adultcontent, 'false', 'adultcontent' ); + is( $osd->syndicationright, 'open', 'syndicationright' ); my $queries = $osd->query; - is( scalar @$queries, 1, 'number of query objects' ); - is( $queries->[ 0 ]->role, 'example', 'role' ); - is( $queries->[ 0 ]->searchTerms, 'cat', 'searchTerms' ); + is( scalar @$queries, 1, 'number of query objects' ); + is( $queries->[ 0 ]->role, 'example', 'role' ); + is( $queries->[ 0 ]->searchTerms, 'cat', 'searchTerms' ); my $images = $osd->image; - is( scalar @$images, 2, 'number of image objects' ); - is( $images->[ 0 ]->height, 64, 'height' ); - is( $images->[ 0 ]->width, 64, 'width' ); - is( $images->[ 0 ]->type, 'image/png', 'content type' ); + is( scalar @$images, 2, 'number of image objects' ); + is( $images->[ 0 ]->height, 64, 'height' ); + is( $images->[ 0 ]->width, 64, 'width' ); + is( $images->[ 0 ]->type, 'image/png', 'content type' ); is( $images->[ 0 ]->url, 'http://example.com/websearch.png', 'url' ); - is( $images->[ 1 ]->height, 16, 'height' ); - is( $images->[ 1 ]->width, 16, 'width' ); - is( $images->[ 1 ]->type, 'image/vnd.microsoft.icon', 'content type' ); + is( $images->[ 1 ]->height, 16, 'height' ); + is( $images->[ 1 ]->width, 16, 'width' ); + is( $images->[ 1 ]->type, 'image/vnd.microsoft.icon', 'content type' ); is( $images->[ 1 ]->url, 'http://example.com/websearch.ico', 'url' ); # count the urls @@ -127,19 +130,22 @@ use_ok( 'WWW::OpenSearch::Description' ); my $osd = WWW::OpenSearch::Description->new( $description ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); - is( $osd->shortname, 'Electronics', 'shortname' ); - is( $osd->longname, 'Amazon Electronics', 'longname' ); - is( $osd->description, 'Search for electronics on Amazon.com.', 'descrpiton' ); - is( $osd->tags, 'amazon electronics', 'tags' ); - is( $osd->contact, 'dewitt@unto.net', 'contact' ); - is( $osd->format, 'http://a9.com/-/spec/opensearchrss/1.0/', 'format' ); - is( $osd->image, 'http://www.unto.net/search/amazon_electronics.gif', 'image' ); - is( $osd->samplesearch, 'ipod', 'samplesearch' ); - is( $osd->developer, 'DeWitt Clinton', 'developer' ); + is( $osd->shortname, 'Electronics', 'shortname' ); + is( $osd->longname, 'Amazon Electronics', 'longname' ); + is( $osd->description, 'Search for electronics on Amazon.com.', + 'descrpiton' ); + is( $osd->tags, 'amazon electronics', 'tags' ); + is( $osd->contact, 'dewitt@unto.net', 'contact' ); + is( $osd->format, 'http://a9.com/-/spec/opensearchrss/1.0/', 'format' ); + is( $osd->image, 'http://www.unto.net/search/amazon_electronics.gif', + 'image' ); + is( $osd->samplesearch, 'ipod', 'samplesearch' ); + is( $osd->developer, 'DeWitt Clinton', 'developer' ); is( $osd->attribution, 'Product and search data © 2005, Amazon, Inc., - All Rights Reserved', 'attribution' ); - is( $osd->syndicationright, 'open', 'syndicationright' ); - is( $osd->adultcontent, 'false', 'adultcontent' ); + All Rights Reserved', 'attribution' + ); + is( $osd->syndicationright, 'open', 'syndicationright' ); + is( $osd->adultcontent, 'false', 'adultcontent' ); # count the urls is( $osd->urls, 1, 'urls' ); diff --git a/t/11-url.t b/t/11-url.t index 9b1e2d8..69ce833 100644 --- a/t/11-url.t +++ b/t/11-url.t @@ -20,12 +20,15 @@ use_ok( 'WWW::OpenSearch::Url' ); is( $osd->ns, 'http://a9.com/-/spec/opensearch/1.1/', 'namespace' ); is( $osd->urls, 1, 'number of urls' ); - my( $url ) = $osd->urls; + my ( $url ) = $osd->urls; isa_ok( $url, 'WWW::OpenSearch::Url' ); is( $url->type, 'application/rss+xml', 'content type' ); is( lc $url->method, 'get', 'method' ); - is( $url->template, 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', 'template' ); - my $result = $url->prepare_query( { searchTerms => 'x', startPage => 1 } ); + is( $url->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', + 'template' ); + my $result + = $url->prepare_query( { searchTerms => 'x', startPage => 1 } ); is( $result, 'http://example.com/?q=x&pw=1&format=rss', 'prepare_query' ); } @@ -57,7 +60,9 @@ use_ok( 'WWW::OpenSearch::Url' ); isa_ok( $url, 'WWW::OpenSearch::Url' ); is( $url->type, 'application/rss+xml', 'content type' ); is( lc $url->method, 'get', 'method' ); - is( $url->template, 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', 'template' ); + is( $url->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', + 'template' ); } { @@ -65,20 +70,45 @@ use_ok( 'WWW::OpenSearch::Url' ); isa_ok( $url, 'WWW::OpenSearch::Url' ); is( $url->type, 'application/atom+xml', 'content type' ); is( lc $url->method, 'get', 'method' ); - is( $url->template, 'http://example.com/?q={searchTerms}&pw={startPage}&format=atom', 'template' ); + is( $url->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=atom', + 'template' + ); } { my $url = $osd->url->[ 2 ]; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( $url->type, 'text/html', 'content type' ); - is( lc $url->method, 'post', 'method' ); - is( $url->template, 'https://intranet/search?format=html', 'template' ); - is_deeply( $url->params, { s => '{searchTerms}', o => '{startIndex}', c => '{itemsPerPage}', l => '{language}' }, 'params' ); - my( $result, $post ) = $url->prepare_query( { searchTerms => 'x', startIndex => '1', itemsPerPage => 1, language => 'en' } ); - is( $result, 'https://intranet/search?format=html', 'prepare_query (uri)' ); + is( $url->type, 'text/html', 'content type' ); + is( lc $url->method, 'post', 'method' ); + is( $url->template, 'https://intranet/search?format=html', + 'template' ); + is_deeply( + $url->params, + { s => '{searchTerms}', + o => '{startIndex}', + c => '{itemsPerPage}', + l => '{language}' + }, + 'params' + ); + my ( $result, $post ) = $url->prepare_query( + { searchTerms => 'x', + startIndex => '1', + itemsPerPage => 1, + language => 'en' + } + ); + is( $result, + 'https://intranet/search?format=html', + 'prepare_query (uri)' + ); $post = { @$post }; - is_deeply( $post, { s => 'x', o => 1, c => 1, l => 'en' }, 'prepare_query (params)' ); + is_deeply( + $post, + { s => 'x', o => 1, c => 1, l => 'en' }, + 'prepare_query (params)' + ); } } @@ -95,9 +125,12 @@ use_ok( 'WWW::OpenSearch::Url' ); is( $osd->ns, 'http://a9.com/-/spec/opensearchrss/1.0/', 'namespace' ); is( $osd->urls, 1, 'number of urls' ); - my( $url ) = $osd->urls; + my ( $url ) = $osd->urls; isa_ok( $url, 'WWW::OpenSearch::Url' ); is( lc $url->method, 'get', 'method' ); - is( $url->template, 'http://www.unto.net/aws?q={searchTerms}&searchindex=Electronics&flavor=osrss&itempage={startPage}', 'template' ); + is( $url->template, + 'http://www.unto.net/aws?q={searchTerms}&searchindex=Electronics&flavor=osrss&itempage={startPage}', + 'template' + ); } diff --git a/t/13-request.t b/t/13-request.t index 24c9396..41c56b1 100644 --- a/t/13-request.t +++ b/t/13-request.t @@ -27,7 +27,8 @@ use_ok( 'WWW::OpenSearch::Request' ); my $osd = WWW::OpenSearch::Description->new( $description ); { - my $req = WWW::OpenSearch::Request->new( $osd->url->[ 2 ], { searchTerms => 'iPod' } ); + my $req = WWW::OpenSearch::Request->new( $osd->url->[ 2 ], + { searchTerms => 'iPod' } ); isa_ok( $req, 'WWW::OpenSearch::Request' ); is( lc $req->method, 'post', 'method' ); is( $req->uri, 'https://intranet/search?format=html', 'uri' ); @@ -35,7 +36,8 @@ use_ok( 'WWW::OpenSearch::Request' ); } { - my $req = WWW::OpenSearch::Request->new( $osd->url->[ 1 ], { searchTerms => 'iPod' } ); + my $req = WWW::OpenSearch::Request->new( $osd->url->[ 1 ], + { searchTerms => 'iPod' } ); isa_ok( $req, 'WWW::OpenSearch::Request' ); is( lc $req->method, 'get', 'method' ); is( $req->uri, 'http://example.com/?q=iPod&pw=1&format=atom', 'uri' ); diff --git a/t/98_pod.t b/t/98_pod.t index 3afe2fa..437887a 100644 --- a/t/98_pod.t +++ b/t/98_pod.t @@ -1,4 +1,4 @@ -use Test::More; -eval "use Test::Pod 1.00"; -plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; -all_pod_files_ok(); \ No newline at end of file +use Test::More; +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok(); diff --git a/t/99_pod_coverage.t b/t/99_pod_coverage.t index 73a83b0..45298e0 100644 --- a/t/99_pod_coverage.t +++ b/t/99_pod_coverage.t @@ -1,4 +1,5 @@ -use Test::More; -eval "use Test::Pod::Coverage 1.00"; -plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; -all_pod_coverage_ok(); \ No newline at end of file +use Test::More; +eval "use Test::Pod::Coverage 1.00"; +plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" + if $@; +all_pod_coverage_ok(); -- 2.11.0