lib/Drogo/Dispatcher/Attributes.pm

filter: Statementstmt 90.2% 46 / 51 Branchbran 67.8% 19 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 83.1% 74 / 89 CC 17 SCAR 21.2
CC
17
Cov
82%
MODIFY_CODE_ATTRIBUTES
14.5
get_package_dispatch_flags
5.0
get_dispatch_flags
3.0
CRAP 8.3
« blib/lib/Drogo/Server/Nginx.pm ↑ Summary blib/lib/Drogo/Server/PSGI.pm »
1 1 ▶use attributes;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Drogo::Dispatcher::Attributes;
6  
7 =head1 NAME
8  
9 Drogo::Dispatcher::Attributes
10  
11 Attributes:
12 Index, Page, Action, ActionMatch, ActionRegex
13  
14 =head1 Synopsis
15  
16 Code attributes.
17  
18 =head1 Methods
19  
20 =cut
21  
22 1 our ( %dispatch_flags, %cached_flags );
23  
24 sub MODIFY_CODE_ATTRIBUTES
25 7 ▶{
Subroutine MODIFY_CODE_ATTRIBUTES: called CC=11 SCAR=26.7
26 7 my ($pack, $ref, @attr) = @_;
27  
28 7 for my $attr ( @attr ) {
29  
30 # ensure a $dispatch_flags{$pack} hashref, always
31 $dispatch_flags{$pack} = { }
32 7 ▶ unless exists $dispatch_flags{$pack};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Drogo::Dispatcher::Attributes::dispatch_flags{$pack} 2 5 7
33  
34 7 ▶ if ($attr eq 'Index')
Branch: 5 branches
BranchTrueFalseTotal
if ($attr eq 'Index') { } 2 5 7
elsif ($attr eq 'Action') { } 2 3 5
elsif ($attr eq 'ActionMatch') { } 2 1 3
elsif ($attr =~ /^ActionRegex/) { } 1 0 1
elsif ($attr =~ /^Path/) { } 0 0 0
35 {
36 2 $dispatch_flags{$pack}{$ref} = 'index';
37 }
38 elsif ($attr eq 'Action')
39 {
40 2 $dispatch_flags{$pack}{$ref} = 'action';
41 }
42 elsif ($attr eq 'ActionMatch')
43 {
44 2 $dispatch_flags{$pack}{$ref} = 'action_match';
45 }
46 elsif ($attr =~ /^ActionRegex/)
47 {
48 1 ▶ if ($attr =~ /^ActionRegex\(['"](.*)['"]\)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^ActionRegex\(['"](.*)['"]\)$/) { } 1 0 1
49 {
50 1 my $regex = $1;
51  
52 1 eval { qr/$regex/ };
53 1 ▶ die "Invalid ActionRegex in $pack (ref) $attr: $@\n"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
54 if $@;
55  
56 1 $dispatch_flags{$pack}{$ref} = "action_regex-${regex}";
57 }
58 else
59 {
60 0 die "Invalid ActionRegex in $pack (ref): $attr\n";
61 }
62 }
63 elsif ($attr =~ /^Path/)
64 {
65 0 my $desc;
66 0 ▶ $desc = $1 if $attr =~ /\(['"](.*?)['"]\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /\(['"](.*?)['"]\)$/ 0 0 0
67  
68 0 $dispatch_flags{$pack}{$ref} = "path-${desc}";
69 }
70 }
71  
72 7 return ();
73 }
74  
75 0 ▶sub FETCH_CODE_ATTRIBUTES { $dispatch_flags{shift}{shift} }
Subroutine FETCH_CODE_ATTRIBUTES: not called CC=1 SCAR=6.9
76  
77 =head2 get_dispatch_flags
78  
79 Returns all autoflags specific to a package with inheritance.
80  
81 =cut
82  
83 sub get_dispatch_flags
84 13 ▶{
Subroutine get_dispatch_flags: called CC=3 SCAR=11.0
Pod documented
85 13 my $self = shift;
86 13 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 13 13
87  
88 $cached_flags{$class} = $class->get_package_dispatch_flags
89 13 ▶ unless exists $cached_flags{$class};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Drogo::Dispatcher::Attributes::cached_flags{$class} 2 11 13
90  
91 13 return $cached_flags{$class};
92 }
93  
94 =head2 get_package_dispatch_flags
95  
96 Get autoflags, only specific to the called package.
97  
98 =cut
99  
100 sub get_package_dispatch_flags
101 2 ▶{
Subroutine get_package_dispatch_flags: called CC=5 SCAR=16.1
Pod documented
102 2 my $self = shift;
103 2 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 2 2
104 2 my @code_refs = keys %{$dispatch_flags{$class}};
105  
106 2 my %flag_methods;
107 {
108 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
109 2 for my $key (keys %{"${class}::"})
110 {
111 27 my $code_ref = "${class}::${key}";
112  
113 27 ▶ if (defined &$code_ref)
Branch: 1 branch
BranchTrueFalseTotal
if (defined &$code_ref) 10 17 27
114 {
115 10 my $code = \&$code_ref;
116  
117 $flag_methods{"$key"} = $dispatch_flags{"$class"}{"$code"}
118 10 ▶ if grep { "$code" eq "$_" } @code_refs;
Branch: 1 branch
BranchTrueFalseTotal
if grep {"$code" eq "$_";} @code_refs 7 3 10
119 }
120 }
121 }
122  
123 2 return \%flag_methods;
124 }
125  
126 =head1 AUTHORS
127  
128 Bizowie <http://bizowie.com>
129  
130 =head1 COPYRIGHT AND LICENSE
131  
132 Copyright (C) 2013 Bizowie
133  
134 This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
135  
136 =cut
137  
138 1 1;
« blib/lib/Drogo/Server/Nginx.pm ↑ Summary blib/lib/Drogo/Server/PSGI.pm »