X-Git-Url: http://erislabs.net/gitweb/?p=libwww-opensearch-perl.git;a=blobdiff_plain;f=lib%2FWWW%2FOpenSearch.pm;h=5bc3da3b82c5d0255428f9a8577741f830f7091e;hp=375623ea19ffe716fe7b669fbf981b28512480d4;hb=a075f6895864bf1851d0526b64ca2e4b5ba118da;hpb=e6583e346fb587eda90892a92b7f34be0a940900 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;