API/Meta/Method/APIMethod.pm

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