Imported Upstream version 0.11
[libwww-opensearch-perl.git] / lib / WWW / OpenSearch / Request.pm
1 package WWW::OpenSearch::Request;
2
3 use strict;
4 use warnings;
5
6 use base qw( HTTP::Request Class::Accessor::Fast );
7
8 use HTTP::Request::Common ();
9
10 __PACKAGE__->mk_accessors( qw( opensearch_url opensearch_params ) );
11
12 =head1 NAME
13
14 WWW::OpenSearch::Request - Encapsulate an opensearch request
15
16 =head1 SYNOPSIS
17
18 =head1 DESCRIPTION
19
20 =head1 CONSTRUCTOR
21
22 =head2 new( $url, \%params )
23
24 =head1 METHODS
25
26 =head2 clone( )
27
28 =head1 ACCESSORS
29
30 =over 4
31
32 =item * opensearch_url
33
34 =item * opensearch_params
35
36 =back
37
38 =head1 AUTHOR
39
40 =over 4
41
42 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
43
44 =back
45
46 =head1 COPYRIGHT AND LICENSE
47
48 Copyright 2007 by Tatsuhiko Miyagawa and Brian Cassidy
49
50 This library is free software; you can redistribute it and/or modify
51 it under the same terms as Perl itself. 
52
53 =cut
54
55 sub new {
56     my( $class, $os_url, $params ) = @_;
57
58     my( $uri, $post ) = $os_url->prepare_query( $params );
59
60     my $self;
61     if( lc $os_url->method eq 'post' ) {
62         $self = HTTP::Request::Common::POST( $uri, $post );
63         bless $self, $class;
64     }
65     else {
66         $self = $class->SUPER::new( $os_url->method => $uri );
67     }
68
69     $self->opensearch_url( $os_url );
70     $self->opensearch_params( $params );
71
72     return $self;
73 }
74
75 sub clone {
76     my $self  = shift;
77     my $clone = bless $self->SUPER::clone, ref( $self );
78
79     $clone->opensearch_url( $self->opensearch_url );
80     $clone->opensearch_params( $self->opensearch_params );
81
82     return $clone;
83 }
84
85 1;