blib/lib/Catalyst/Plugin/ActionPaths.pm

filter: Statementstmt 16.0% 14 / 87 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 12.5% 19 / 152 CC 32 SCAR 68.4
CC
32
Cov
10%
get_action_paths
1056.0
BEGIN
1.0
BEGIN
1.0
CRAP 938.8
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Catalyst::Plugin::ActionPaths;
4 1 $Catalyst::Plugin::ActionPaths::VERSION = '0.01';
5 1 ▶use Encode 'decode_utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #ABSTRACT: get Catalyst actions with example paths included!
9  
10  
11 sub get_action_paths
12 0 ▶{
Subroutine get_action_paths: not called CC=32 SCAR=69.6
Pod documented
13 0 my $c = shift;
14 0 ▶ die 'get_action_paths() requires a Catalyst context as an argument'
Branch: 1 branch
BranchTrueFalseTotal
unless $c and $c->isa("Catalyst") 0 0 0
Condition0%0/3
$c and $c->isa("Catalyst")
!ll&&!rl&&r
000
MC/DC0%0/2
$c and $c->isa("Catalyst")
$c $c->isa("Catalyst")
Truth table0%0/3
A and B
A= $cB= $c->isa("Catalyst")
ABresult
0X0
100
111
15 unless $c && $c->isa('Catalyst');
16  
17 0 my @actions = ();
18  
19 0 for my $dt (@{$c->dispatcher->dispatch_types})
20 {
21 0 ▶ if (ref $dt eq 'Catalyst::DispatchType::Path')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $dt eq 'Catalyst::DispatchType::Path') { } 0 0 0
elsif (ref $dt eq 'Catalyst::DispatchType::Chained') { } 0 0 0
22 {
23 # taken from Catalyst::DispatchType::Path
24 0 foreach my $path ( sort keys %{ $dt->_paths } ) {
25 0 foreach my $action ( @{ $dt->_paths->{$path} } ) {
26 0 my $args = $action->number_of_args;
27 0 ▶ my $parts = defined($args) ? '/*' x $args : '/...';
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 0 0 0
28  
29 0 my $display_path = "/$path/$parts";
30 0 $display_path =~ s{/{1,}}{/}g;
31 0 $display_path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; # deconvert urlencoded for pretty view·
32 0 $display_path = decode_utf8 $display_path; # URI does encoding
33 0 $action->{path} = $display_path;
34 0 push @actions, $action;
35 }
36 }
37 }
38 elsif (ref $dt eq 'Catalyst::DispatchType::Chained')
39 {
40 # taken from Catalyst::DispatchType::Chained
41 0 ENDPOINT: foreach my $endpoint (
42 0 sort { $a->reverse cmp $b->reverse }
43 0 @{ $dt->_endpoints }
44 ) {
45 0 my $args = $endpoint->list_extra_info->{Args};
46 0 ▶ my @parts = (defined($endpoint->attributes->{Args}[0]) ? (("*") x $args) : '...');
Branch: 1 branch
BranchTrueFalseTotal
defined $endpoint->attributes->{'Args'}[0] ? : 0 0 0
47 0 my @parents = ();
48 0 my $parent = "DUMMY";
49 0 my $extra = $dt->_list_extra_http_methods($endpoint);
50 0 my $consumes = $dt->_list_extra_consumes($endpoint);
51 0 my $scheme = $dt->_list_extra_scheme($endpoint);
52 0 my $curr = $endpoint;
53 0 my $action = $endpoint;
54 0 ▶ while ($curr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curr) 0 0 0
55 0 ▶ if (my $cap = $curr->list_extra_info->{CaptureArgs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cap = $curr->list_extra_info->{"CaptureArgs"}) 0 0 0
56 0 unshift(@parts, (("*") x $cap));
57 }
58 0 ▶ if (my $pp = $curr->attributes->{PathPart}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pp = $curr->attributes->{"PathPart"}) 0 0 0
59 0 ▶ unshift(@parts, $pp->[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $pp->[0] and length $pp->[0] 0 0 0
Condition0%0/3
defined $pp->[0] and length $pp->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pp->[0] and length $pp->[0]
defined $pp->[0] length $pp->[0]
Truth table0%0/3
A and B
A= defined $pp->[0]B= length $pp->[0]
ABresult
0X0
100
111
60 if (defined $pp->[0] && length $pp->[0]);
61 }
62 0 $parent = $curr->attributes->{Chained}->[0];
63 0 $curr = $dt->_actions->{$parent};
64 0 ▶ unshift(@parents, $curr) if $curr;
Branch: 1 branch
BranchTrueFalseTotal
if $curr 0 0 0
65 }
66 0 ▶ if ($parent ne '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent ne "/") 0 0 0
67 0 next ENDPOINT;
68 }
69 0 my @rows;
70 0 foreach my $p (@parents) {
71 0 my $name = "/${p}";
72  
73 0 ▶ if (defined(my $extra = $dt->_list_extra_http_methods($p))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $extra = $dt->_list_extra_http_methods($p))) 0 0 0
74 0 $name = "${extra} ${name}";
75 }
76 0 ▶ if (defined(my $cap = $p->list_extra_info->{CaptureArgs})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cap = $p->list_extra_info->{"CaptureArgs"})) 0 0 0
77 0 ▶ if($p->has_captures_constraints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->has_captures_constraints) { } 0 0 0
78 0 my $tc = join ',', @{$p->captures_constraints};
79 0 $name .= " ($tc)";
80 } else {
81 0 $name .= " ($cap)";
82 }
83 }
84 0 ▶ if (defined(my $ct = $p->list_extra_info->{Consumes})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ct = $p->list_extra_info->{"Consumes"})) 0 0 0
85 0 $name .= ' :'.$ct;
86 }
87 0 ▶ if (defined(my $s = $p->list_extra_info->{Scheme})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $s = $p->list_extra_info->{"Scheme"})) 0 0 0
88 0 $scheme = uc $s;
89 }
90  
91 0 ▶ unless ($p eq $parents[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p eq $parents[0]) 0 0 0
92 0 $name = "-> ${name}";
93 }
94 0 push(@rows, [ '', $name ]);
95 }
96  
97 0 ▶ if($endpoint->has_args_constraints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endpoint->has_args_constraints) { } 0 0 0
98 0 my $tc = join ',', @{$endpoint->args_constraints};
99 0 $endpoint .= " ($tc)";
100 } else {
101 0 ▶ $endpoint .= defined($endpoint->attributes->{Args}[0]) ? " ($args)" : " (...)";
Branch: 1 branch
BranchTrueFalseTotal
defined $endpoint->attributes->{'Args'}[0] ? : 0 0 0
102 }
103 0 ▶ push(@rows, [ '', (@rows ? "=> " : '').($extra ? "$extra " : ''). ($scheme ? "$scheme: ":'')."/${endpoint}". ($consumes ? " :$consumes":"" ) ]);
Branch: 4 branches
BranchTrueFalseTotal
@rows ? : 0 0 0
$extra ? : 0 0 0
$scheme ? : 0 0 0
$consumes ? : 0 0 0
104 0 my @display_parts = map { $_ =~s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; decode_utf8 $_ } @parts;
105 0 ▶ $rows[0][0] = join('/', '', @display_parts) || '/';
Condition0%0/2
join('/', '', @display_parts) || '/'
l!l
00
MC/DC0%0/1
join('/', '', @display_parts) || '/'
join('/', '', @display_parts)
Truth table0%0/2
A
A= join('/', '', @display_parts)
Aresult
11
00
106 0 $action->{path} = $rows[0][0];
107 0 push @actions, $action;
108 }
109 }
110 }
111 0 return \@actions;
112 }
113  
114 1 1;
115  
116 __END__
↑ Summary