Spore/Meta/Method/Spore.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 100% 3 / 3 totaltotal 82.0% 55 / 67 CC 5 SCAR 5.3
CC
5
Cov
78%
find_spore_method_by_name
3.1
__ANON__
2.1
__ANON__
2.1
CRAP 1.7
« Spore/Meta/Types.pm ↑ Summary Spore/Middleware/Auth/Header.pm »
1 package Net::HTTP::Spore::Meta::Method::Spore;
2 27 $Net::HTTP::Spore::Meta::Method::Spore::VERSION = '0.09';
3 # ABSTRACT: declare API method
4  
5 27 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 ▶use Net::HTTP::Spore::Meta::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use MooseX::Types::Moose qw/Str ArrayRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 has local_spore_methods => (
12 traits => ['Array'],
13 is => 'rw',
14 isa => ArrayRef [Str],
15 required => 1,
16 61 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 27 auto_deref => 1,
18 handles => {
19 _find_spore_method_by_name => 'first',
20 _add_spore_method => 'push',
21 get_all_spore_methods => 'elements',
22 },
23 );
24  
25 27 ▶sub find_spore_method_by_name {
Subroutine find_spore_method_by_name: called CC=3 SCAR=11.4
Pod documented
26 27 my ($meta, $name) = @_;
27 27 ▶ my $method_name = $meta->_find_spore_method_by_name(sub {/^$name$/});
Subroutine __ANON__: called CC=1 SCAR=0.0
28 27 ▶ return unless $method_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $method_name 0 27 27
29 27 my $method = $meta->find_method_by_name($method_name);
30 27 ▶ if ($method->isa('Class::MOP::Method::Wrapped')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->isa('Class::MOP::Method::Wrapped')) { } 27 0 27
31 27 return $method->get_original_method;
32 }
33 else {
34 0 return $method;
35 }
36 }
37  
38 0 ▶sub remove_spore_method {
Subroutine remove_spore_method: not called CC=1 SCAR=6.9
Pod documented
39 0 my ($meta, $name) = @_;
40 0 my @methods = grep { $_ ne $name } $meta->get_all_spore_methods;
41 0 $meta->local_spore_methods(\@methods);
42 0 $meta->remove_method($name);
43 }
44  
45 127 ▶before add_spore_method => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
46 127 my ($meta, $name) = @_;
47 127 ▶ if ($meta->_find_spore_method_by_name(sub {$_ eq $name})) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->_find_spore_method_by_name(sub { $_ eq $name; } )) 0 127 127
48 0 confess "method '$name' is already delcared in ".$meta->name;
49 }
50 27 };
51  
52 127 ▶sub add_spore_method {
Subroutine add_spore_method: called CC=1 SCAR=0.0
Pod documented
53 127 my ($meta, $name, %options) = @_;
54  
55 127 my $code = delete $options{code};
56  
57 # $meta->_trace_msg( '-> attach '
58 # . $name . ' ('
59 # . $options{method} . ' => '
60 # . $options{path}
61 # . ')' );
62  
63 127 $meta->add_method(
64 $name,
65 Net::HTTP::Spore::Meta::Method->wrap(
66 name => $name,
67 package_name => $meta->name,
68 body => $code,
69 %options
70 ),
71 );
72 125 $meta->_add_spore_method($name);
73 }
74  
75 125 ▶after add_spore_method => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
76 125 my ($meta, $name) = @_;
77 $meta->add_before_method_modifier(
78 $name,
79 27 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
80 27 my $self = shift;
81 27 ▶ die Net::HTTP::Spore::Response->new(599, [], {error => "'base_url' have not been defined"}) unless $self->base_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->base_url 0 27 27
82 }
83 125 );
84 27 };
85  
86 27 1;
87  
88 __END__
« Spore/Meta/Types.pm ↑ Summary Spore/Middleware/Auth/Header.pm »