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
---
abstract: Search A9 OpenSearch compatible engines
-author: Brian Cassidy <bricas@cpan.org>
+author:
+ - Brian Cassidy <bricas@cpan.org>
+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
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
-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';
requires 'Encode';
requires 'URI';
requires 'URI::Template';
-requires 'Test::More';
+
+test_requires 'Test::More';
auto_install;
WriteAll;
# 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
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
#line 1
package Module::Install::Base;
-$VERSION = '0.65';
+$VERSION = '0.68';
# Suspend handler for "redefined" warnings
BEGIN {
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
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 $/; <MAKEFILE> };
- 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 $/; <MAKEFILE> };
+ 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
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
};
}
-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;
}
{
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;
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.65';
+ $VERSION = '0.68';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
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
=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;
=cut
sub new {
- my( $class, @rest ) = @_;
+ my ( $class, @rest ) = @_;
return $class->SUPER::new(
agent => join( '/', __PACKAGE__, $WWW::OpenSearch::VERSION ),
@rest,
sub request {
my $self = shift;
- my $request = shift; ;
+ my $request = shift;
my $response = $self->SUPER::request( $request, @_ );
# allow regular HTTP::Requests to flow through
=head2 AdultContent( )
+=head2 Attribution( )
+
=head2 Contact( )
=head2 Description( )
=head2 Format( )
+=head2 InputEncoding( )
+
=head2 Image( )
+=head2 Language( )
+
=head2 LongName( )
+=head2 OutputEncoding( )
+
=head2 Query( )
=head2 SampleSearch( )
=cut
-for( @columns ) {
+for ( @columns ) {
no strict 'refs';
my $col = lc;
*$_ = \&$col;
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: $@";
}
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';
}
$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;
}
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;
}
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 ];
sub get_url_by_type {
my $self = shift;
my $type = shift;
-
- for( $self->urls ) {
+
+ for ( $self->urls ) {
return $_ if $_->type eq $type;
- };
-
+ }
+
return;
}
=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;
}
}
sub clone {
- my $self = shift;
+ my $self = shift;
my $clone = bless $self->SUPER::clone, ref( $self );
$clone->opensearch_url( $self->opensearch_url );
sub new {
my $class = shift;
my $response = shift;
-
+
my $self = bless $response, $class;
return $self unless $self->is_success;
-
+
$self->parse_response;
-
+
return $self;
}
return if XML::Feed->errstr;
$self->feed( $feed );
-
+
$self->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;
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;
}
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;
}
=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;
return $url, [ %$post ];
}
-
+
return $url;
}
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;
}
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;
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
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
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' );
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' );
}
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' );
}
{
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)'
+ );
}
}
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'
+ );
}
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' );
}
{
- 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' );
-use Test::More;\r
-eval "use Test::Pod 1.00";\r
-plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;\r
-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();
-use Test::More;\r
-eval "use Test::Pod::Coverage 1.00";\r
-plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;\r
-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();