OX.pm

filter: Statementstmt 95.0% 96 / 101 Branchbran 81.5% 31 / 38 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 92.0% 23 / 25 Podpod 87.5% 7 / 8 totaltotal 90.4% 160 / 177 CC 23 SCAR 15.6
CC
23
Cov
91%
router
12.1
mount
5.5
wrap
4.0
CRAP 4.8
« OX/Meta/Role/Application/ToRole.pm ↑ Summary OX/Application/Role/RouterConfig.pm »
1 package OX;
2 41 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 $OX::AUTHORITY = 'cpan:STEVAN';
4 }
5 41 $OX::VERSION = '0.14';
6 41 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: the hardest working two letters in Perl
9  
10 41 ▶use Bread::Board::Declare 0.11 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 41 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 41 ▶use Class::Load 0.10 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 41 ▶use Moose::Util 'find_meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 41 ▶use namespace::autoclean ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 41 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 41 my ($import, undef, $init_meta) = Moose::Exporter->build_import_methods(
19 also => ['Moose', 'Bread::Board::Declare'],
20 with_meta => [qw(router)],
21 as_is => [qw(route mount wrap wrap_if as literal)],
22 install => [qw(unimport)],
23 class_metaroles => {
24 class => ['OX::Meta::Role::Class'],
25 },
26 base_class_roles => [
27 'OX::Application::Role::Router::Path::Router',
28 'OX::Application::Role::RouteBuilder',
29 'OX::Application::Role::Sugar',
30 ],
31 );
32  
33 95 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
34 95 my ($package, $args) = @_;
35 95 ▶ my $into = $args && $args->{into} ? $args->{into} : caller;
Branch: 1 branch
BranchTrueFalseTotal
$args && $args->{'into'} ? : 1 94 95
Condition66%2/3
$args and $args->{"into"}
!ll&&!rl&&r
9401
MC/DC50%1/2
$args and $args->{"into"}
$args $args->{"into"}
Truth table66%2/3
A and B
A= $argsB= $args->{"into"}
ABresult
0X0
100
111
36 95 namespace::autoclean->import(-cleanee => $into);
37 95 goto $import;
38 }
39  
40 95 ▶sub init_meta {
Subroutine init_meta: called CC=1 SCAR=0.0
Pod undocumented
41 95 my $package = shift;
42 95 my %options = @_;
43 95 $options{base_class} = 'OX::Application';
44 95 Moose->init_meta(%options);
45 95 $package->$init_meta(%options);
46 }
47  
48  
49 111 ▶sub as (&) { $_[0] }
Subroutine as: called CC=1 SCAR=0.0
Pod documented
50  
51  
52 41 our $CURRENT_CLASS;
53 41 our %INITIALIZED_CLASSES;
54  
55 90 ▶sub router {
Subroutine router: called CC=12 SCAR=24.9
Pod documented
56 90 my ($top_meta, @args) = @_;
57  
58 90 ▶ my $meta = $CURRENT_CLASS
Branch: 1 branch
BranchTrueFalseTotal
$OX::CURRENT_CLASS ? : 8 82 90
59 ? _new_router_meta($CURRENT_CLASS)
60 : $top_meta;
61  
62 confess "Only one top level router is allowed"
63 90 ▶ if $INITIALIZED_CLASSES{$meta->name};
Branch: 1 branch
BranchTrueFalseTotal
if $OX::INITIALIZED_CLASSES{$meta->name} 1 89 90
64 89 $INITIALIZED_CLASSES{$meta->name} = 1;
65  
66 89 my $explicit_routebuilders;
67 89 ▶ if (ref($args[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq "ARRAY") 5 84 89
68 5 $meta->_clear_route_builders;
69 5 $meta->add_route_builder($_) for @{ $args[0] };
70 5 shift @args;
71 5 $explicit_routebuilders = 1;
72 }
73 89 my ($body, %params) = @args;
74  
75 89 ▶ if (!ref($body)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $body) { } 3 86 89
elsif (builtin::blessed($body)) { } 1 85 86
elsif (ref $body eq 'CODE') { } 85 0 85
76 3 load_class($body);
77 0 ▶ $meta->add_method(router_class => sub { $body });
Subroutine __ANON__: not called CC=1 SCAR=0.4
Subroutine router_class: called CC=1 SCAR=0.4
78 3 ▶ $meta->add_method(router_dependencies => sub { \%params });
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine router_dependencies: called CC=1 SCAR=0.0
79 }
80 elsif (blessed($body)) {
81 0 ▶ $meta->add_method(build_router => sub { $body });
Subroutine __ANON__: not called CC=1 SCAR=0.4
Subroutine build_router: called CC=1 SCAR=0.4
82 }
83 elsif (ref($body) eq 'CODE') {
84 85 ▶ if (!$explicit_routebuilders) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($explicit_routebuilders) 80 5 85
85 80 ▶ if ($CURRENT_CLASS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OX::CURRENT_CLASS) { } 7 73 80
86 7 for my $route_builder ($CURRENT_CLASS->route_builders) {
87 19 $meta->add_route_builder($route_builder);
88 }
89 }
90 else {
91 73 $meta->add_route_builder('OX::RouteBuilder::ControllerAction');
92 73 $meta->add_route_builder('OX::RouteBuilder::HTTPMethod');
93 73 $meta->add_route_builder('OX::RouteBuilder::Code');
94 }
95 }
96  
97 85 local $CURRENT_CLASS = $meta;
98 85 $body->();
99 }
100 else {
101 0 confess "Unknown argument to 'router': $body";
102 }
103  
104 88 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 9 79 88
105 9 return $meta->new_object->to_app;
106 }
107 }
108  
109 9 ▶sub _new_router_meta {
Subroutine _new_router_meta: called CC=1 SCAR=0.0
110 9 my ($meta) = @_;
111  
112 9 return find_meta($meta)->name->create_anon_class(
113 superclasses => [$meta->name],
114 );
115 }
116  
117  
118 182 ▶sub route {
Subroutine route: called CC=2 SCAR=7.0
Pod documented
119 182 my ($path, $action_spec, %params) = @_;
120  
121 182 ▶ confess "route called outside of a router block"
Branch: 1 branch
BranchTrueFalseTotal
unless $OX::CURRENT_CLASS 0 182 182
122 unless $CURRENT_CLASS;
123  
124 182 my ($class, $route_spec) = $CURRENT_CLASS->route_builder_for($action_spec);
125 173 $CURRENT_CLASS->add_route(
126 path => $path,
127 class => $class,
128 route_spec => $route_spec,
129 params => \%params,
130 definition_location => $CURRENT_CLASS->name,
131 );
132 }
133  
134  
135 40 ▶sub mount {
Subroutine mount: called CC=5 SCAR=17.1
Pod documented
136 40 my ($path, $mount, %deps) = @_;
137  
138 40 ▶ confess "mount called outside of a router block"
Branch: 1 branch
BranchTrueFalseTotal
unless $OX::CURRENT_CLASS 0 40 40
139 unless $CURRENT_CLASS;
140  
141 40 my %default = (
142 path => $path,
143 definition_location => $CURRENT_CLASS->name,
144 );
145  
146 40 my %extra;
147 40 ▶ if (!ref($mount)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $mount) { } 9 31 40
elsif (builtin::blessed($mount)) { } 0 31 31
elsif (ref $mount eq 'CODE') { } 31 0 31
148 9 %extra = (
149 class => $mount,
150 dependencies => \%deps,
151 );
152 }
153 elsif (blessed($mount)) {
154 0 %extra = (
155 app => $mount->to_app,
156 );
157 }
158 elsif (ref($mount) eq 'CODE') {
159 31 %extra = (
160 app => $mount,
161 )
162 }
163 else {
164 0 confess "Unknown mount $mount";
165 }
166  
167 40 $CURRENT_CLASS->add_mount(%default, %extra);
168 }
169  
170  
171 21 ▶sub wrap {
Subroutine wrap: called CC=4 SCAR=13.9
Pod documented
172 21 my ($lifecycle, $middleware, %deps);
173 21 ▶ if (@_ % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) { } 20 1 21
174 20 ($middleware, %deps) = @_;
175 }
176 else {
177 1 ($lifecycle, $middleware, %deps) = @_;
178 }
179  
180 21 ▶ confess "wrap called outside of a router block"
Branch: 1 branch
BranchTrueFalseTotal
unless $OX::CURRENT_CLASS 0 21 21
181 unless $CURRENT_CLASS;
182  
183 21 ▶ $CURRENT_CLASS->add_middleware(
Branch: 1 branch
BranchTrueFalseTotal
defined $lifecycle ? : 1 20 21
184 middleware => $middleware,
185 dependencies => \%deps,
186 (defined $lifecycle
187 ? (lifecycle => $lifecycle)
188 : ()),
189 );
190 }
191  
192  
193 2 ▶sub wrap_if {
Subroutine wrap_if: called CC=2 SCAR=7.1
Pod documented
194 2 my ($condition, $middleware, %deps) = @_;
195  
196 2 ▶ confess "wrap_if called outside of a router block"
Branch: 1 branch
BranchTrueFalseTotal
unless $OX::CURRENT_CLASS 0 2 2
197 unless $CURRENT_CLASS;
198  
199 2 $CURRENT_CLASS->add_middleware(
200 condition => $condition,
201 middleware => $middleware,
202 dependencies => \%deps,
203 );
204 }
205  
206  
207 4 ▶sub literal {
Subroutine literal: called CC=1 SCAR=0.0
Pod documented
208 4 my ($value) = @_;
209 4 return Bread::Board::Literal->new(
210 name => '__ANON__',
211 value => $value,
212 );
213 }
214  
215  
216 41 1;
217  
218 __END__
« OX/Meta/Role/Application/ToRole.pm ↑ Summary OX/Application/Role/RouterConfig.pm »