blib/lib/CGI/Application/Plugin/DeclareREST.pm

filter: Statementstmt 78.3% 58 / 74 Branchbran 66.6% 4 / 6 Conditioncond 25.0% 6 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 75.0% 12 / 16 Podpod 100% 9 / 9 totaltotal 61.3% 89 / 145 CC 12 SCAR 11.8
CC
12
Cov
65%
add_route
6.0
put
6.0
patch
6.0
CRAP 3.3
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package CGI::Application::Plugin::DeclareREST;
4 {
5 2 $CGI::Application::Plugin::DeclareREST::VERSION = '0.01';
6 }
7 # ABSTRACT: Declare RESTful API for CGI::Application
8  
9 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use REST::Utils qw( request_method );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Routes::Tiny 0.11;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our @ISA = qw( Exporter );
14 2 our @EXPORT = qw(
15 get post del put patch any
16 match captures
17 add_route
18 );
19  
20 2 our %EXPORT_TAGS = (
21 http_methods => [qw( get post del put patch )],
22 );
23  
24 2 our %routes;
25  
26  
27 sub add_route {
28 0 ▶ my $self = shift;
Subroutine add_route: not called CC=2 SCAR=17.9
Pod documented
29 0 my $class = ref $self;
30
31 0 ▶ my $router = $routes{ $class } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition0%0/3
$CGI::Application::Plugin::DeclareREST::routes{$class} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$class} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$class} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table0%0/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$class}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
32 0 return $router->add_route( @_ );
33 }
34  
35  
36 sub get {
37 6 ▶ my $sub = pop;
Subroutine get: called CC=2 SCAR=7.0
Pod documented
38 6 my ($path, %args) = @_;
39
40 6 my $caller = caller();
41 6 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition66%2/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
510
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table66%2/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
42 6 return $router->add_route($path, method => 'get', name => $sub, %args);
43 }
44  
45  
46 sub post {
47 1 ▶ my $sub = pop;
Subroutine post: called CC=2 SCAR=7.2
Pod documented
48 1 my ($path, %args) = @_;
49
50 1 my $caller = caller();
51 1 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition33%1/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
100
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table33%1/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
52 1 return $router->add_route($path, method => 'post', name => $sub, %args );
53 }
54  
55  
56 sub del {
57 1 ▶ my $sub = pop;
Subroutine del: called CC=2 SCAR=7.2
Pod documented
58 1 my ($path, %args) = @_;
59
60 1 my $caller = caller();
61 1 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition33%1/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
100
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table33%1/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
62 1 return $router->add_route($path, method => 'delete', name => $sub, %args );
63 }
64  
65  
66 sub put {
67 0 ▶ my $sub = pop;
Subroutine put: not called CC=2 SCAR=17.9
Pod documented
68 0 my ($path, %args) = @_;
69
70 0 my $caller = caller();
71 0 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition0%0/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table0%0/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
72 0 return $router->add_route($path, method => 'put', name => $sub, %args );
73 }
74  
75  
76 sub patch {
77 0 ▶ my $sub = pop;
Subroutine patch: not called CC=2 SCAR=17.9
Pod documented
78 0 my ($path, %args) = @_;
79
80 0 my $caller = caller();
81 0 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition0%0/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table0%0/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
82 0 return $router->add_route($path, method => 'patch', name => $sub, %args );
83 }
84  
85  
86 sub any {
87 1 ▶ my $sub = pop;
Subroutine any: called CC=2 SCAR=7.2
Pod documented
88 1 my ($methods, $path, %args) = @_;
89
90 1 my $caller = caller();
91 1 ▶ my $router = $routes{ $caller } ||= Routes::Tiny->new( strict_trailing_slash => 0 );
Condition33%1/3
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
l!l&&r!l&&!r
100
MC/DC0%0/2
$CGI::Application::Plugin::DeclareREST::routes{$caller} ||= "Routes::Tiny"->new("strict_trailing_slash", 0)
$CGI::Application::Plugin::DeclareREST::routes{$caller} "Routes::Tiny"->new("strict_trailing_slash", 0)
Truth table33%1/3
A ||= B
A= $CGI::Application::Plugin::DeclareREST::routes{$caller}B= "Routes::Tiny"->new("strict_trailing_slash", 0)
ABresult
1X1
011
000
92 1 return $router->add_route($path, method => $methods, name => $sub, %args);
93 }
94  
95 sub import {
96 2 ▶ my $caller = caller;
Subroutine import: called CC=1 SCAR=0.0
97
98 2 $caller->add_callback('prerun', \&_routes_prerun);
99 2 goto &Exporter::import;
100 }
101  
102 sub _routes_prerun {
103 10 ▶ my $self = shift;
Subroutine _routes_prerun: called CC=5 SCAR=16.7
104 10 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
1000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
105  
106 10 ▶ if(defined $self->query->param( $self->mode_param )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->query->param($self->mode_param)) 0 10 10
107 # OK, we got the query param, to select the right runmode:
108 # We should passthrough to allow normal behaviour
109 0 return;
110 }
111  
112 10 my $method = request_method($self->query);
113  
114 10 my $r = $routes{$class};
115 10 ▶ if($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 10 0 10
116 10 my $match = $r->match($self->query->path_info, method => $method );
117 10 ▶ if($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 9 1 10
118 9 $self->run_modes( $match->name => $match->name );
119 9 $self->prerun_mode( $match->name );
120 9 $self->{__MATCH} = $match;
121 9 return;
122 }
123 }
124 }
125  
126  
127 sub match {
128 0 ▶ (shift)->{__MATCH};
Subroutine match: not called CC=1 SCAR=6.9
Pod documented
129 }
130  
131  
132 sub captures {
133 7 ▶ (shift)->{__MATCH}->captures;
Subroutine captures: called CC=1 SCAR=0.0
Pod documented
134 }
135  
136 2 1;
137  
138 __END__
↑ Summary