line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::TraitFor::Request::Params::Hashed; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28161
|
use namespace::autoclean; |
|
1
|
|
|
|
|
24217
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
580
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use MooseX::Types::Moose qw/ HashRef /; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Catalyst::TraitFor::Request::Params::Hashed - Access to parameters |
12
|
|
|
|
|
|
|
like C<name[index]> as hashes for Catalyst::Request. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version is 0.03 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# application class |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
package TestApp; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Moose; |
26
|
|
|
|
|
|
|
use namespace::autoclean; |
27
|
|
|
|
|
|
|
use Catalyst qw/ ......... /; |
28
|
|
|
|
|
|
|
extends 'Catalyst'; |
29
|
|
|
|
|
|
|
use CatalystX::RoleApplicator; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->apply_request_class_roles(qw/ |
32
|
|
|
|
|
|
|
Catalyst::TraitFor::Request::Params::Hashed |
33
|
|
|
|
|
|
|
/); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# controller class |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
package TestApp::Controller::Test; |
39
|
|
|
|
|
|
|
......... |
40
|
|
|
|
|
|
|
# query string was like |
41
|
|
|
|
|
|
|
# site[name1]=100&site[name1]=150&site[name2]=200 |
42
|
|
|
|
|
|
|
my $site = $c->req->hashed_params->{site}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# $site is hashref: |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# $site = { |
47
|
|
|
|
|
|
|
# name1 => [100, 150], |
48
|
|
|
|
|
|
|
# name2 => 200, |
49
|
|
|
|
|
|
|
# } |
50
|
|
|
|
|
|
|
......... |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
You can access C<hashed_parameters>, C<hashed_query_parameters>, |
55
|
|
|
|
|
|
|
C<hashed_body_parameters> to get access to parameters as to hashes. |
56
|
|
|
|
|
|
|
Also you can use C<hashes_params>, C<hashed_query_params> and |
57
|
|
|
|
|
|
|
C<hashed_body_params> as shortcuts. Or, if you too lazy, you can use |
58
|
|
|
|
|
|
|
C<hparams>, C<hquery_params> and C<hbody_params> :) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Note, that this trait gives you read-only version of C<params>, |
61
|
|
|
|
|
|
|
C<query_params> and C<body_params> respectively. Also note, that |
62
|
|
|
|
|
|
|
any change to any of three above <WILL NOT HAVE> any effect to all |
63
|
|
|
|
|
|
|
of C<hashed*params>. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has hashed_parameters => ( |
68
|
|
|
|
|
|
|
is => 'ro', |
69
|
|
|
|
|
|
|
isa => HashRef, |
70
|
|
|
|
|
|
|
lazy => 1, |
71
|
|
|
|
|
|
|
builder => '_build_hashed_parameters', |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has hashed_query_parameters => ( |
75
|
|
|
|
|
|
|
is => 'ro', |
76
|
|
|
|
|
|
|
isa => HashRef, |
77
|
|
|
|
|
|
|
lazy => 1, |
78
|
|
|
|
|
|
|
builder => '_build_hashed_query_parameters', |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has hashed_body_parameters => ( |
82
|
|
|
|
|
|
|
is => 'ro', |
83
|
|
|
|
|
|
|
isa => HashRef, |
84
|
|
|
|
|
|
|
lazy => 1, |
85
|
|
|
|
|
|
|
builder => '_build_hashed_body_parameters', |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub __build_hashed { |
89
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
90
|
|
|
|
|
|
|
$params = {%$params}; # make copy |
91
|
|
|
|
|
|
|
for my $key ( keys %$params ) { |
92
|
|
|
|
|
|
|
next unless $key =~ m/^([^[]+)\[(.*)\]$/; |
93
|
|
|
|
|
|
|
$params->{$1}{$2} = delete $params->{$key}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
return $params; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _build_hashed_parameters { |
99
|
|
|
|
|
|
|
my ($self) = @_; |
100
|
|
|
|
|
|
|
return $self->__build_hashed( $self->parameters ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _build_hashed_query_parameters { |
104
|
|
|
|
|
|
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
return $self->__build_hashed( $self->query_parameters ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _build_hashed_body_parameters { |
109
|
|
|
|
|
|
|
my ($self) = @_; |
110
|
|
|
|
|
|
|
return $self->__build_hashed( $self->body_parameters ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 hashed_params |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 hparams |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 hashed_query_params |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 hquery_params |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 hashed_body_params |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 hbody_params |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub hashed_params { shift->hashed_parameters } |
130
|
|
|
|
|
|
|
sub hparams { shift->hashed_parameters } |
131
|
|
|
|
|
|
|
sub hashed_query_params { shift->hashed_query_parameters } |
132
|
|
|
|
|
|
|
sub hquery_params { shift->hashed_query_parameters } |
133
|
|
|
|
|
|
|
sub hashed_body_params { shift->hashed_body_parameters } |
134
|
|
|
|
|
|
|
sub hbody_params { shift->hashed_body_parameters } |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 TODO |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Write tests. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<Catalyst>, L<Catalyst::Request>, C<Catalyst::TraitFor::Request::BrowserDetect> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SUPPORT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * Report bugs or feature requests |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-TraitFor-Request-Params-Hashed> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L<http://www.assembla.com/spaces/Catalyst-TraitFor-Request-Params-Hashed/tickets> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * Git repository |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
git clone git://git.assembla.com/Catalyst-TraitFor-Request-Params-Hashed.git |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Oleg Kostyuk, C<< <cub#cpan.org> >> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Copyright 2009 Oleg Kostyuk. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
169
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
170
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; # End of Catalyst::TraitFor::Request::Params::Hashed |