blib/lib/Magpie/Resource.pm

filter: Statementstmt 82.2% 37 / 45 Branchbran 83.3% 5 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 46.6% 7 / 15 Podpod 0.0% 0 / 11 totaltotal 62.3% 53 / 85 CC 8 SCAR 9.8
CC
8
Cov
80%
methods_implemented
5.0
get_entity_id
3.2
method_not_allowed
2.0
CRAP 2.7
« blib/lib/Magpie/Resource/File.pm ↑ Summary blib/lib/Magpie/SymbolTable.pm »
1 package Magpie::Resource;
2 49 $Magpie::Resource::VERSION = '1.163200';
3 # ABSTRACT: Abstract base class for all resource types;
4  
5 49 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 extends 'Magpie::Component';
7 49 with 'Magpie::Dispatcher::RequestMethod';
8 49 ▶use Magpie::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 49 __PACKAGE__->register_events(Magpie::Dispatcher::RequestMethod::events());
11  
12 49 has '+_trait_namespace' => ( default => 'Magpie::Plugin::Resource' );
13  
14 49 has produces => (
15 is => 'ro',
16 isa => 'Str',
17 required => 1,
18 default => 'text/plain',
19 );
20  
21 49 has consumes => (
22 is => 'ro',
23 isa => 'Str',
24 required => 1,
25 default => 'text/plain',
26 );
27  
28 49 has data => (
29 is => 'rw',
30 predicate => 'has_data',
31 clearer => 'clear_data',
32 );
33  
34 49 has state => (
35 is => 'rw',
36 isa => 'Str',
37 default => 'uninitialized',
38 required => 1,
39 );
40  
41 has dependencies => (
42 traits => ['Hash'],
43 is => 'rw',
44 isa => 'HashRef[HashRef]',
45 118 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 49 handles => {
47 add_dependency => 'set',
48 get_dependency => 'get',
49 delete_dependency => 'delete',
50 has_dependencies => 'count',
51 },
52 );
53  
54 2 ▶sub methods_implemented {
Subroutine methods_implemented: called CC=5 SCAR=16.1
Pod undocumented
55 2 my $self = shift;
56 2 my %implemented = ();
57 2 foreach my $class ( $self->meta->linearized_isa ) {
58 8 ▶ next if $class =~ /^(Magpie|Moose)::/;
Branch: 1 branch
BranchTrueFalseTotal
if $class =~ /^(Magpie|Moose)::/ 7 1 8
59 1 foreach (HTTP_METHODS){
60 9 ▶ $implemented{$_}++ if $class->meta->has_method($_);
Branch: 1 branch
BranchTrueFalseTotal
if $class->meta->has_method($_) 1 8 9
61 }
62 }
63 2 return ( keys( %implemented ));
64 }
65  
66 2 ▶sub method_not_allowed {
Subroutine method_not_allowed: called CC=2 SCAR=6.9
Pod undocumented
67 2 my $self = shift;
68 2 ▶ my $method = $self->plack_request->method || 'unknown';
Condition100%2/2
$self->plack_request->method || 'unknown'
l!l
11
MC/DC100%1/1
$self->plack_request->method || 'unknown'
$self->plack_request->method
Truth table100%2/2
A
A= $self->plack_request->method
Aresult
11
00
69 2 my @allowed = $self->methods_implemented;
70 2 $self->set_error(
71 { status_code => 405,
72 reason => "Method '$method' not allowed.",
73 additional_headers => [ Allow => \@allowed ],
74 }
75 );
76 2 return DONE;
77 }
78  
79 1 ▶sub GET {
Subroutine GET: called CC=1 SCAR=0.0
Pod undocumented
80 1 shift->method_not_allowed(@_);
81 }
82  
83 0 ▶sub POST {
Subroutine POST: not called CC=1 SCAR=6.9
Pod undocumented
84 0 shift->method_not_allowed(@_);
85 }
86  
87 0 ▶sub PUT {
Subroutine PUT: not called CC=1 SCAR=6.9
Pod undocumented
88 0 shift->method_not_allowed(@_);
89 }
90  
91 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
92 0 shift->method_not_allowed(@_);
93 }
94  
95 0 ▶sub HEAD {
Subroutine HEAD: not called CC=1 SCAR=6.9
Pod undocumented
96 0 shift->method_not_allowed(@_);
97 }
98  
99 0 ▶sub OPTIONS {
Subroutine OPTIONS: not called CC=1 SCAR=6.9
Pod undocumented
100 0 shift->method_not_allowed(@_);
101 }
102  
103 0 ▶sub TRACE {
Subroutine TRACE: not called CC=1 SCAR=6.9
Pod undocumented
104 0 shift->method_not_allowed(@_);
105 }
106  
107 0 ▶sub PATCH {
Subroutine PATCH: not called CC=1 SCAR=6.9
Pod undocumented
108 0 shift->method_not_allowed(@_);
109 }
110  
111 0 ▶sub CONNECT {
Subroutine CONNECT: not called CC=1 SCAR=6.9
Pod undocumented
112 0 shift->method_not_allowed(@_);
113 }
114  
115 # convenience for container-based Resources
116 3 ▶sub get_entity_id {
Subroutine get_entity_id: called CC=3 SCAR=11.6
Pod undocumented
117 3 my $self = shift;
118 3 my $path = $self->request->path_info;
119 3 ▶ return undef if $path =~ /\/$/;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[/$] 0 3 3
120 3 my @steps = split '/', $path;
121 3 ▶ my $id = $self->request->param('id') || pop @steps;
Condition33%1/3
$self->request->param('id') || pop @steps
l!l&&r!l&&!r
030
MC/DC0%0/2
$self->request->param('id') || pop @steps
$self->request->param('id') pop @steps
Truth table33%1/3
A || B
A= $self->request->param('id')B= pop @steps
ABresult
1X1
011
000
122 3 return $id;
123 }
124  
125 49 1;
126  
127 __END__
« blib/lib/Magpie/Resource/File.pm ↑ Summary blib/lib/Magpie/SymbolTable.pm »