1 package WWW::OpenSearch::Url;
6 use base qw( Class::Accessor::Fast );
10 __PACKAGE__->mk_accessors( qw( type template method params ns ) );
14 WWW::OpenSearch::Url - Object to represent a target URL
22 =head2 new( [%options] )
26 =head2 prepare_query( [ \%params ] )
48 =item * Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
50 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
54 =head1 COPYRIGHT AND LICENSE
56 Copyright 2005-2009 by Tatsuhiko Miyagawa and Brian Cassidy
58 This library is free software; you can redistribute it and/or modify
59 it under the same terms as Perl itself.
64 my ( $class, %options ) = @_;
66 $options{ method } ||= 'GET';
67 $options{ template } = URI::Template->new( $options{ template } );
69 my $self = $class->SUPER::new( \%options );
75 my ( $self, $params ) = @_;
76 my $tmpl = $self->template;
78 for ( qw( startIndex startPage ) ) {
79 $params->{ $_ } = 1 if !defined $params->{ $_ };
81 $params->{ language } ||= '*';
82 $params->{ outputEncoding } ||= 'UTF-8';
83 $params->{ inputEncoding } ||= 'UTF-8';
85 # fill the uri template
86 my $url = $tmpl->process( %$params );
88 # attempt to handle POST
89 if ( $self->method eq 'post' ) {
90 my $post = $self->params;
91 for my $key ( keys %$post ) {
92 $post->{ $key } =~ s/{(.+)}/$params->{ $1 } || ''/eg;
95 return $url, [ %$post ];