OX/Role.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 83.3% 15 / 18 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 87.0% 94 / 108 CC 15 SCAR 17.6
CC
15
Cov
91%
router
11.1
import
3.3
_new_router_meta
3.0
CRAP 5.8
« OX/Meta/Role/Application/ToClass.pm ↑ Summary OX/Meta/Role/Application/ToRole.pm »
1 package OX::Role;
2 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 $OX::Role::AUTHORITY = 'cpan:STEVAN';
4 }
5 8 $OX::Role::VERSION = '0.14';
6 8 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: declare roles for your OX applications
9  
10 8 ▶use Bread::Board::Declare 0.11 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Moose::Util 'find_meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use namespace::autoclean ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 8 ▶use OX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 8 my ($import) = Moose::Exporter->build_import_methods(
20 also => ['Moose::Role', 'Bread::Board::Declare'],
21 with_meta => [qw(router)],
22 as_is => [\&OX::route, \&OX::mount, \&OX::as, \&OX::literal],
23 install => [qw(unimport init_meta)],
24 role_metaroles => {
25 role => ['OX::Meta::Role::Role'],
26 application_to_class => ['OX::Meta::Role::Application::ToClass'],
27 application_to_role => ['OX::Meta::Role::Application::ToRole'],
28 application_to_instance => ['OX::Meta::Role::Application::ToInstance'],
29 },
30 );
31  
32 20 ▶sub import {
Subroutine import: called CC=3 SCAR=12.0
33 20 my ($package, $args) = @_;
34 20 ▶ my $into = $args && $args->{into} ? $args->{into} : caller;
Branch: 1 branch
BranchTrueFalseTotal
$args && $args->{'into'} ? : 0 20 20
Condition33%1/3
$args and $args->{"into"}
!ll&&!rl&&r
2000
MC/DC0%0/2
$args and $args->{"into"}
$args $args->{"into"}
Truth table33%1/3
A and B
A= $argsB= $args->{"into"}
ABresult
0X0
100
111
35 20 namespace::autoclean->import(-cleanee => $into);
36 20 goto $import;
37 }
38  
39  
40  
41 25 ▶sub router {
Subroutine router: called CC=11 SCAR=24.1
Pod documented
42 25 my ($top_meta, @args) = @_;
43  
44 25 ▶ my $meta = $OX::CURRENT_CLASS
Branch: 1 branch
BranchTrueFalseTotal
$OX::CURRENT_CLASS ? : 5 20 25
45 ? _new_router_meta($OX::CURRENT_CLASS)
46 : $top_meta;
47  
48 25 ▶ confess "Only one top level router is allowed"
Branch: 1 branch
BranchTrueFalseTotal
if not $OX::CURRENT_CLASS and $meta->has_route_builders 0 25 25
Condition66%2/3
not $OX::CURRENT_CLASS and $meta->has_route_builders
!ll&&!rl&&r
5200
MC/DC0%0/2
not $OX::CURRENT_CLASS and $meta->has_route_builders
not $OX::CURRENT_CLASS $meta->has_route_builders
Truth table66%2/3
not(A) and B
A= not $OX::CURRENT_CLASSB= $meta->has_route_builders
ABresult
0X0
100
111
49 if !$OX::CURRENT_CLASS && $meta->has_route_builders;
50  
51 25 ▶ if (ref($args[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq "ARRAY") 1 24 25
52 1 $meta->add_route_builder($_) for @{ $args[0] };
53 1 shift @args;
54 }
55 25 my ($body) = @args;
56  
57 25 ▶ if (ref($body) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $body eq 'CODE') { } 25 0 25
58 25 ▶ if (!$meta->has_route_builders) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->has_route_builders) 24 1 25
59 24 ▶ if ($OX::CURRENT_CLASS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OX::CURRENT_CLASS) { } 5 19 24
60 5 for my $route_builder ($OX::CURRENT_CLASS->route_builders) {
61 15 $meta->add_route_builder($route_builder);
62 }
63 }
64 else {
65 19 $meta->add_route_builder('OX::RouteBuilder::ControllerAction');
66 19 $meta->add_route_builder('OX::RouteBuilder::HTTPMethod');
67 19 $meta->add_route_builder('OX::RouteBuilder::Code');
68 }
69 }
70  
71 25 local $OX::CURRENT_CLASS = $meta;
72 25 $body->();
73 }
74 else {
75 0 confess "Roles only support the block form of 'router', not $body";
76 }
77  
78 25 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 5 20 25
79 5 return $meta->new_object->to_app;
80 }
81 }
82  
83 8 my $default_class_meta;
84  
85 5 ▶sub _new_router_meta {
Subroutine _new_router_meta: called CC=3 SCAR=11.0
86 5 my ($meta) = @_;
87  
88 5 ▶ if (!$meta->isa('Moose::Meta::Role')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->isa("Moose::Meta::Role")) 1 4 5
89 1 return OX::_new_router_meta($meta);
90 }
91  
92 4 ▶ $default_class_meta ||= do {
Condition66%2/3
$default_class_meta ||= do { "OX"->import({"into", "OX::Role::__DEFAULT_META__"}); find_meta("OX::Role::__DEFAULT_META__") }
l!l&&r!l&&!r
310
MC/DC0%0/2
$default_class_meta ||= do { "OX"->import({"into", "OX::Role::__DEFAULT_META__"}); find_meta("OX::Role::__DEFAULT_META__") }
$default_class_meta do { "OX"->import({"into", "OX::Role::__DEFAULT_META__"}); find_meta("OX::Role::__DEFAULT_META__") }
Truth table66%2/3
A ||= B
A= $default_class_metaB= do { "OX"->import({"into", "OX::Role::__DEFAULT_META__"}); find_meta("OX::Role::__DEFAULT_META__") }
ABresult
1X1
011
000
93 1 OX->import({ into => "OX::Role::__DEFAULT_META__" });
94 1 find_meta('OX::Role::__DEFAULT_META__');
95 };
96  
97 4 my $new = find_meta($default_class_meta)->name->create_anon_class(
98 superclasses => [$default_class_meta->superclasses],
99 roles => [$meta->name],
100 );
101 4 $new->clear_app_state;
102 4 return $new;
103 }
104  
105  
106  
107  
108  
109 8 1;
110  
111 __END__
« OX/Meta/Role/Application/ToClass.pm ↑ Summary OX/Meta/Role/Application/ToRole.pm »