X-Git-Url: http://erislabs.net/gitweb/?p=libwww-opensearch-perl.git;a=blobdiff_plain;f=lib%2FWWW%2FOpenSearch.pm;h=4906dbefb269f7e0da4a2b462bb8232a91c504a7;hp=86ad45cc5be4d11e65f0ca65c0a24f82d4f8affc;hb=e021488790d05654b6a8f5e13896b29aad7da610;hpb=1fc70f0d6badbef9bb483990d761d1446d52cbb2 diff --git a/lib/WWW/OpenSearch.pm b/lib/WWW/OpenSearch.pm index 86ad45c..4906dbe 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.11'; +our $VERSION = '0.17'; =head1 NAME @@ -97,17 +97,13 @@ WWW::OpenSearch::Response object. Method defaults to 'GET'. =head1 AUTHOR -=over 4 - -=item * Tatsuhiko Miyagawa Emiyagawa@bulknews.netE +Brian Cassidy Ebricas@cpan.orgE -=item * Brian Cassidy Ebricas@cpan.orgE - -=back +Tatsuhiko Miyagawa Emiyagawa@bulknews.netE =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Tatsuhiko Miyagawa and Brian Cassidy +Copyright 2005-2013 by Tatsuhiko Miyagawa and Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -115,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;