Interchange6/Plugin/Interchange5/Request.pm

filter: Statementstmt 32.5% 14 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 17.3% 4 / 23 Podpod 100% 18 / 18 totaltotal 39.1% 36 / 92 CC 5 SCAR 15.7
CC
5
Cov
27%
environment
20.0
__ANON__
6.0
header
2.0
CRAP 4.8
« HTTP/ClientDetect/Location.pm ↑ Summary HTTP/ClientDetect/Language.pm »
1 package Interchange6::Plugin::Interchange5::Request;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Interchange6::Plugin::Interchange5::Request - Mimic Dancer::Request inside IC5
11  
12 =head1 VERSION
13  
14 Version 0.01
15  
16 =cut
17  
18 1 our $VERSION = '0.01';
19  
20  
21 =head1 SYNOPSIS
22  
23 Quick summary of what the module does.
24  
25 In a tag (shipped as dancer_request.tag)
26  
27 use Interchange6::Plugin::Interchange5::Request;
28 my %env = %{::http()->{env}};
29 return Interchange6::Plugin::Interchange5::Request->new(env => \%env);
30 ...
31  
32 Somewhere else
33  
34 my $req = $Tag->dancer_request;
35 $req->header('Accept-Language');
36 $req->accept_language;
37 ....
38  
39  
40 =head1 ACCESSORS
41  
42 =head2 env
43  
44 =cut
45  
46 has env => (is => 'ro',
47 required => 1,
48 isa => sub {
49 0 ▶ die unless ref($_[0]) eq 'HASH';
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 0 0
50 1 });
51  
52 =head1 METHODS
53  
54 =head2 environment($name)
55  
56 Look into the environment variables, with the following routine:
57 first, we uppercase the name and replace any non-alpha and non-digit
58 character with the underscore. Then we look into the environment. If
59 not found, we try to prepend HTTP_. Return undef in nothing is found.
60  
61 =head2 header($name)
62  
63 Alias for environment
64  
65 =cut
66  
67 sub header {
68 0 ▶ my ($self, $name) = @_;
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
69 0 return $self->environment($name);
70 }
71  
72 sub environment {
73 0 ▶ my ($self, $name) = @_;
Subroutine environment: not called CC=4 SCAR=30.0
Pod documented
74 0 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
75 0 $name =~ s/[^a-zA-Z0-9_]/_/g;
76 0 $name = uc($name);
77 0 my $http_name = "HTTP_" . $name;
78 0 my $env = $self->env;
79 0 ▶ if (exists $env->{$name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $env->{$name}) { } 0 0 0
elsif (exists $env->{$http_name}) { } 0 0 0
80 0 return $env->{$name};
81 }
82 elsif (exists $env->{$http_name}) {
83 0 return $env->{$http_name};
84 }
85 else {
86 0 return;
87 }
88 }
89  
90  
91 =head2 SHORTCUTS
92  
93 The following methods are just shortcuts for the C<environment> method.
94  
95 =over 4
96  
97 =item accept
98  
99 =item accept_charset
100  
101 =item accept_encoding
102  
103 =item accept_language
104  
105 =item accept_type
106  
107 =item agent (alias for "user_agent")
108  
109 =item connection
110  
111 =item forwarded_for_address
112  
113 =item forwarded_protocol
114  
115 =item forwarded_host
116  
117 =item host
118  
119 =item keep_alive
120  
121 =item path_info
122  
123 =item referer
124  
125 =item remote_address
126  
127 =item user_agent
128  
129 =back
130  
131 =cut
132  
133 0 ▶sub accept { return shift->environment("accept") }
Subroutine accept: not called CC=1 SCAR=6.9
Pod documented
134  
135 0 ▶sub accept_charset { return shift->environment("accept_charset") }
Subroutine accept_charset: not called CC=1 SCAR=6.9
Pod documented
136  
137 0 ▶sub accept_encoding { return shift->environment("accept_encoding") }
Subroutine accept_encoding: not called CC=1 SCAR=6.9
Pod documented
138  
139 0 ▶sub accept_language { return shift->environment("accept_language") }
Subroutine accept_language: not called CC=1 SCAR=6.9
Pod documented
140  
141 0 ▶sub accept_type { return shift->environment("accept_type") }
Subroutine accept_type: not called CC=1 SCAR=6.9
Pod documented
142  
143 0 ▶sub agent { return shift->environment("user_agent") }
Subroutine agent: not called CC=1 SCAR=6.9
Pod documented
144  
145 0 ▶sub connection { return shift->environment("connection") }
Subroutine connection: not called CC=1 SCAR=6.9
Pod documented
146  
147 0 ▶sub forwarded_for_address { return shift->environment("forwarded_for_address") }
Subroutine forwarded_for_address: not called CC=1 SCAR=6.9
Pod documented
148  
149 0 ▶sub forwarded_protocol { return shift->environment("forwarded_protocol") }
Subroutine forwarded_protocol: not called CC=1 SCAR=6.9
Pod documented
150  
151 0 ▶sub forwarded_host { return shift->environment("forwarded_host") }
Subroutine forwarded_host: not called CC=1 SCAR=6.9
Pod documented
152  
153 0 ▶sub host { return shift->environment("host") }
Subroutine host: not called CC=1 SCAR=6.9
Pod documented
154  
155 0 ▶sub keep_alive { return shift->environment("keep_alive") }
Subroutine keep_alive: not called CC=1 SCAR=6.9
Pod documented
156  
157 0 ▶sub path_info { return shift->environment("path_info") }
Subroutine path_info: not called CC=1 SCAR=6.9
Pod documented
158  
159 0 ▶sub referer { return shift->environment("referer") }
Subroutine referer: not called CC=1 SCAR=6.9
Pod documented
160  
161 0 ▶sub remote_address { return shift->environment("remote_addr") }
Subroutine remote_address: not called CC=1 SCAR=6.9
Pod documented
162  
163 0 ▶sub user_agent { return shift->environment("user_agent") }
Subroutine user_agent: not called CC=1 SCAR=6.9
Pod documented
164  
165 =head1 AUTHOR
166  
167 Marco Pessotto, C<< <melmothx at gmail.com> >>
168  
169 =head1 BUGS
170  
171 Please report any bugs or feature requests to C<bug-interchange6-plugin-autodetect at rt.cpan.org>, or through
172 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Interchange6-Plugin-Autodetect>. I will be notified, and then you'll
173 automatically be notified of progress on your bug as I make changes.
174  
175  
176  
177  
178 =head1 SUPPORT
179  
180 You can find documentation for this module with the perldoc command.
181  
182 perldoc Interchange6::Plugin::Interchange5::Request
183  
184  
185 You can also look for information at:
186  
187 =over 4
188  
189 =item * RT: CPAN's request tracker (report bugs here)
190  
191 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Interchange6-Plugin-Autodetect>
192  
193 =item * AnnoCPAN: Annotated CPAN documentation
194  
195 L<http://annocpan.org/dist/Interchange6-Plugin-Autodetect>
196  
197 =item * CPAN Ratings
198  
199 L<http://cpanratings.perl.org/d/Interchange6-Plugin-Autodetect>
200  
201 =item * Search CPAN
202  
203 L<http://search.cpan.org/dist/Interchange6-Plugin-Autodetect/>
204  
205 =back
206  
207  
208 =head1 ACKNOWLEDGEMENTS
209  
210  
211 =head1 LICENSE AND COPYRIGHT
212  
213 Copyright 2013 Marco Pessotto.
214  
215 This program is free software; you can redistribute it and/or modify it
216 under the terms of either: the GNU General Public License as published
217 by the Free Software Foundation; or the Artistic License.
218  
219 See L<http://dev.perl.org/licenses/> for more information.
220  
221  
222 =cut
223  
224 1 1; # End of Interchange6::Plugin::Interchange5::Request
« HTTP/ClientDetect/Location.pm ↑ Summary HTTP/ClientDetect/Language.pm »