X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2FWWW%2FOpenSearch%2FUrl.pm;h=a69e02adeae9ec30cbebebad09018656957597a1;hb=7ae19f100439de78ed7f3cc77b0fc175c4f07195;hp=6e4c27f7cadcc09b67ac06721d43fcf756eb444a;hpb=0418a266d571b99934f124a6d8e2b1d4b99f22fc;p=libwww-opensearch-perl.git diff --git a/lib/WWW/OpenSearch/Url.pm b/lib/WWW/OpenSearch/Url.pm index 6e4c27f..a69e02a 100644 --- a/lib/WWW/OpenSearch/Url.pm +++ b/lib/WWW/OpenSearch/Url.pm @@ -53,7 +53,7 @@ WWW::OpenSearch::Url - Object to represent a target URL =head1 COPYRIGHT AND LICENSE -Copyright 2007 by Tatsuhiko Miyagawa and Brian Cassidy +Copyright 2005-2009 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. @@ -61,31 +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; - - $params->{ startIndex } ||= 1; - $params->{ startPage } ||= 1; - $params->{ language } ||= '*'; + + for ( qw( startIndex startPage ) ) { + $params->{ $_ } = 1 if !defined $params->{ $_ }; + } + $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; @@ -93,7 +94,7 @@ sub prepare_query { return $url, [ %$post ]; } - + return $url; }