1 package WWW::OpenSearch::Url;
6 use base qw( Class::Accessor::Fast );
11 __PACKAGE__->mk_accessors( qw( type template method params macros ) );
15 WWW::OpenSearch::Url - Object to represent a target URL
23 =head2 new( [%options] )
27 =head2 parse_macros( )
29 =head2 prepare_query( [ \%params ] )
51 =item * Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
53 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
57 =head1 COPYRIGHT AND LICENSE
59 Copyright 2006 by Tatsuhiko Miyagawa and Brian Cassidy
61 This library is free software; you can redistribute it and/or modify
62 it under the same terms as Perl itself.
67 my( $class, %options ) = @_;
69 $options{ method } ||= 'GET';
70 $options{ template } = URI->new( $options{ template } );
72 my $self = $class->SUPER::new( \%options );
81 my %query = $self->method eq 'post'
83 : $self->template->query_form;
87 if( $query{ $_ } =~ /^{(.+)}$/ ) {
92 $self->macros( \%macros );
96 my( $self, $params ) = @_;
97 my $url = $self->template->clone;
99 $params->{ startIndex } ||= 1;
100 $params->{ startPage } ||= 1;
101 $params->{ language } ||= '*';
102 $params->{ outputEncoding } ||= 'UTF-8';
103 $params->{ inputEncoding } ||= 'UTF-8';
105 my $macros = $self->macros;
107 # attempt to handle POST
108 if( $self->method eq 'post' ) {
109 my $post = $self->params;
110 for( keys %$macros ) {
111 $post->{ $macros->{ $_ } } = $params->{ $_ };
113 return [ $url, $post ];
116 my $query = { $url->query_form };
117 for( keys %$macros ) {
118 $query->{ $macros->{ $_ } } = $params->{ $_ };
121 $url->query_form( $query );