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 2007 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 $params->{ startIndex } ||= 1;
79 $params->{ startPage } ||= 1;
80 $params->{ language } ||= '*';
81 $params->{ outputEncoding } ||= 'UTF-8';
82 $params->{ inputEncoding } ||= 'UTF-8';
84 # fill the uri template
85 my $url = $tmpl->process( %$params );
87 # attempt to handle POST
88 if( $self->method eq 'post' ) {
89 my $post = $self->params;
90 for my $key ( keys %$post ) {
91 $post->{ $key } =~ s/{(.+)}/$params->{ $1 } || ''/eg;
94 return $url, [ %$post ];