Nile/HTTP/Request.pm

filter: Statementstmt 23.8% 10 / 42 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 16.6% 2 / 12 Podpod 0.0% 0 / 10 totaltotal 13.9% 12 / 86 CC 9 SCAR 24.2
CC
9
Cov
17%
url_path
30.0
is_ajax
12.0
base_url
6.0
CRAP 11.2
« Nile/Deserializer.pm ↑ Summary Nile/Plugin/Minify.pm »
1 # Copyright Infomation
2 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D.
4 # Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com
5 # Email : mewsoft@cpan.org, support@mewsoft.com
6 # Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved.
7 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 package Nile::HTTP::Request;
9  
10 1 our $VERSION = '0.55';
11 1 our $AUTHORITY = 'cpan:MEWSOFT';
12  
13 =pod
14  
15 =encoding utf8
16  
17 =head1 NAME
18  
19 Nile::HTTP::Request - The HTTP request manager.
20  
21 =head1 SYNOPSIS
22
23 # get app context
24 $app = $self->app;
25  
26 # get request instance which extends CGI::Simple
27 $request = $app->request;
28  
29 $email = $request->param("email");
30  
31 $value = $request->cookie("username");
32  
33 =head1 DESCRIPTION
34  
35 Nile::HTTP::Request - The HTTP request manager.
36  
37 The http request is available as a shared object extending the L<CGI::Simple> module. This means that all methods supported
38 by L<CGI::Simple> is available with the additions to these few methods:
39  
40 base_url
41 abs_url
42 url_path
43 is_ajax
44 is_post
45 is_get
46 is_head
47 is_put
48 is_delete
49 is_patch
50  
51 You access the request object by $self->app->request.
52  
53 =cut
54  
55 1 ▶use Nile::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use MooseX::NonMoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 extends 'CGI::Simple';
58  
59 #Methods: HEAD, POST, GET, PUT, DELETE, PATCH
60 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 0 ▶sub is_ajax {
Subroutine is_ajax: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my $self = shift;
63 0 ▶ if (exists $ENV{HTTP_X_REQUESTED_WITH} && lc($ENV{HTTP_X_REQUESTED_WITH}) eq 'xmlhttprequest') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"HTTP_X_REQUESTED_WITH"} and lc $ENV{"HTTP_X_REQUESTED_WITH"} eq "xmlhttprequest") 0 0 0
Condition0%0/3
exists $ENV{"HTTP_X_REQUESTED_WITH"} and lc $ENV{"HTTP_X_REQUESTED_WITH"} eq "xmlhttprequest"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ENV{"HTTP_X_REQUESTED_WITH"} and lc $ENV{"HTTP_X_REQUESTED_WITH"} eq "xmlhttprequest"
exists $ENV{"HTTP_X_REQUESTED_WITH"} lc $ENV{"HTTP_X_REQUESTED_WITH"} eq "xmlhttprequest"
Truth table0%0/3
A and B
A= exists $ENV{"HTTP_X_REQUESTED_WITH"}B= lc $ENV{"HTTP_X_REQUESTED_WITH"} eq "xmlhttprequest"
ABresult
0X0
100
111
64 0 return 1;
65 }
66 0 return 0;
67 }
68 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 0 ▶sub is_post {lc(shift->request_method) eq "post";}
Subroutine is_post: not called CC=1 SCAR=6.9
Pod undocumented
70 0 ▶sub is_get {lc(shift->request_method) eq "get";}
Subroutine is_get: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub is_head {lc(shift->request_method) eq "head";}
Subroutine is_head: not called CC=1 SCAR=6.9
Pod undocumented
72 0 ▶sub is_put {lc(shift->request_method) eq "put";}
Subroutine is_put: not called CC=1 SCAR=6.9
Pod undocumented
73 0 ▶sub is_delete {lc(shift->request_method) eq "delete";}
Subroutine is_delete: not called CC=1 SCAR=6.9
Pod undocumented
74 0 ▶sub is_patch {lc(shift->request_method) eq "patch";}
Subroutine is_patch: not called CC=1 SCAR=6.9
Pod undocumented
75 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76 0 ▶sub base_url {
Subroutine base_url: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my $self = shift;
78 0 my $url = $self->url();
79 0 my $script = $self->url(-relative=>1);
80 0 $url =~ s/\Q$script\E//;
81 0 ▶ $url = "$url/" if $url !~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[/$] 0 0 0
82 0 return $url;
83 }
84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 0 ▶sub abs_url {
Subroutine abs_url: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $self = shift;
87 0 my $url = $self->url(-absolute=>1);
88 0 my $script = $self->url(-relative=>1);
89 0 $url =~ s/\Q$script\E//;
90 0 ▶ $url = "$url/" if $url !~ m|/$|;
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[/$] 0 0 0
91 0 return $url;
92 }
93 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94 0 ▶sub url_path {
Subroutine url_path: not called CC=5 SCAR=34.0
Pod undocumented
95 0 my $self = shift;
96 0 my $route = "";
97 0 my ($path, $script_name) = $self->script_name =~ m#(.*)/(.*)$#;
98 0 ▶ my ($request_uri, $params) = split(/\?/, ($ENV{REQUEST_URI} || $self->app->env->{REQUEST_URI} || ''));
Condition0%0/5
$ENV{'REQUEST_URI'} || $self->app->env->{'REQUEST_URI'} || ''
l!l
00
$ENV{"REQUEST_URI"} or $self->app->env->{"REQUEST_URI"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'REQUEST_URI'} || $self->app->env->{'REQUEST_URI'} || ''
$ENV{"REQUEST_URI"} $self->app->env->{"REQUEST_URI"}
Truth table0%0/3
A or B
A= $ENV{"REQUEST_URI"}B= $self->app->env->{"REQUEST_URI"}
ABresult
1X1
011
000
99 0 ▶ if ($request_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_uri) 0 0 0
100 0 $route = $request_uri;
101
102 # remove path part from the route
103 0 $route =~ s/^$path//;
104  
105 #remove script name from route
106 0 $route =~ s/$script_name\/?$//;
107 }
108 0 ▶ $route = "$route/" if $route !~ m|/$|;
Branch: 1 branch
BranchTrueFalseTotal
unless $route =~ m[/$] 0 0 0
109 0 return $route;
110 }
111 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112  
113 =pod
114  
115 =head1 Bugs
116  
117 This project is available on github at L<https://github.com/mewsoft/Nile>.
118  
119 =head1 HOMEPAGE
120  
121 Please visit the project's homepage at L<https://metacpan.org/release/Nile>.
122  
123 =head1 SOURCE
124  
125 Source repository is at L<https://github.com/mewsoft/Nile>.
126  
127 =head1 SEE ALSO
128  
129 See L<Nile> for details about the complete framework.
130  
131 =head1 AUTHOR
132  
133 Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org>
134 Website: http://www.mewsoft.com
135  
136 =head1 COPYRIGHT AND LICENSE
137  
138 Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com,
139 L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com>
140  
141 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
142  
143 =cut
144  
145 1 1;
« Nile/Deserializer.pm ↑ Summary Nile/Plugin/Minify.pm »