blib/lib/Froody/Implementation.pm

filter: Statementstmt 93.6% 89 / 95 Branchbran 56.2% 9 / 16 Conditioncond 80.0% 8 / 10 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 94.4% 17 / 18 Podpod 75.0% 6 / 8 totaltotal 86.8% 132 / 152 CC 20 SCAR 11.6
CC
20
Cov
88%
pre_process
6.0
register_plugin
4.2
MODIFY_CODE_ATTRIBUTES
4.1
CRAP 3.2
« blib/lib/Froody/Server/Test.pm ↑ Summary blib/lib/Froody/Repository.pm »
1 package Froody::Implementation;
2  
3 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 Froody::Invoker::Implementation
8 Class::Data::Inheritable
9 Class::Accessor
10 23 );
11  
12 23 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 23 ▶use Froody::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 23 ▶use Froody::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 23 my $logger = Froody::Logger->get_logger("Froody::Implementation");
16  
17 23 our $IMPLEMENTATION_SUPERCLASS = 1;
18 23 our $VERSION = "0.01";
19  
20 # ensure that every context has a new copy of $self, or you'll get nasty
21 # issues when instance vars hang around and break stuff.
22 31 ▶sub create_context {
Subroutine create_context: called CC=1 SCAR=0.0
Pod documented
23 31 my $self = shift;
24 31 $self = $self->new;
25 31 return $self->SUPER::create_context(@_);
26 }
27  
28 23 __PACKAGE__->mk_classdata( 'plugins' );
29 23 __PACKAGE__->mk_classdata( 'plugin_methods' );
30  
31 1 ▶sub register_plugin {
Subroutine register_plugin: called CC=4 SCAR=14.3
Pod documented
32 1 my ($class, $plugin, @args) = @_;
33 1 ▶ $plugin->require or die $@;
Branch: 1 branch
BranchTrueFalseTotal
$plugin->require or die $@ 1 0 1
34 1 ▶ $class->plugins( [] ) unless $class->plugins;
Branch: 1 branch
BranchTrueFalseTotal
unless $class->plugins 1 0 1
35 1 my $instance = $plugin->new($class, @args);
36 1 ▶ Carp::carp("plugin '$plugin' (of class $plugin) is not a plugin")
Branch: 1 branch
BranchTrueFalseTotal
unless $instance->isa("Froody::Plugin") 0 1 1
37 unless $instance->isa('Froody::Plugin');
38 1 push @{$class->plugins}, $instance;
39 }
40  
41 32 ▶sub pre_process {
Subroutine pre_process: called CC=6 SCAR=17.9
Pod documented
42 32 my ($self, $method, $params) = @_;
43
44 32 ▶ for (@{$self->plugins || []}) {
Condition100%2/2
$self->plugins || []
l!l
230
MC/DC100%1/1
$self->plugins || []
$self->plugins
Truth table100%2/2
A
A= $self->plugins
Aresult
11
00
45 2 $_->plugin_pre_process($self, $method, $params);
46 }
47  
48 32 my $ret = $self->SUPER::pre_process($method, $params);
49  
50 # ewwww
51 27 ▶ for (@{$self->plugins || []}) {
Condition100%2/2
$self->plugins || []
l!l
225
MC/DC100%1/1
$self->plugins || []
$self->plugins
Truth table100%2/2
A
A= $self->plugins
Aresult
11
00
52 2 ▶ $_->plugin_post_pre_process($self, $method, $params)
Branch: 1 branch
BranchTrueFalseTotal
if $_->can("plugin_post_pre_process") 0 2 2
53 if $_->can('plugin_post_pre_process');
54 }
55  
56 27 return $ret;
57 }
58  
59 26 ▶sub post_process {
Subroutine post_process: called CC=3 SCAR=11.0
Pod documented
60 26 my $self = shift;
61  
62 26 my $ret = $self->SUPER::post_process(@_);
63 26 ▶ for (reverse @{$self->plugins || []}) {
Condition100%2/2
$self->plugins || []
l!l
224
MC/DC100%1/1
$self->plugins || []
$self->plugins
Truth table100%2/2
A
A= $self->plugins
Aresult
11
00
64 2 $_->plugin_post_process($self, @_);
65 }
66  
67 26 return $ret;
68 }
69  
70 6 ▶sub error_handler {
Subroutine error_handler: called CC=3 SCAR=11.4
Pod documented
71 6 my $self = shift;
72  
73 6 my $ret = $self->SUPER::error_handler(@_);
74 6 ▶ for (reverse @{$self->plugins || []}) {
Condition50%1/2
$self->plugins || []
l!l
06
MC/DC0%0/1
$self->plugins || []
$self->plugins
Truth table50%1/2
A
A= $self->plugins
Aresult
11
00
75 0 $_->plugin_error_handler($self, @_ );
76 }
77  
78 6 return $ret;
79 }
80  
81 sub register_in_repository
82 2 ▶{
Subroutine register_in_repository: called CC=3 SCAR=11.4
Pod undocumented
83 2 my $class = shift;
84 2 my $repository = shift;
85 2 my @filters = shift;
86 2 require Froody::Method;
87 2 @filters = map { Froody::Method->match_to_regex($_) } @filters;
88  
89 2 $repository->register_implementation($class, @filters);
90  
91 0 my @plugin_methods = grep { !eval { $repository->get_method($_->full_name)} }
92 2 ▶ @{ $class->plugin_methods || [] };
Condition50%1/2
$class->plugin_methods || []
l!l
02
MC/DC0%0/1
$class->plugin_methods || []
$class->plugin_methods
Truth table50%1/2
A
A= $class->plugin_methods
Aresult
11
00
93 2 for (@plugin_methods) {
94 # UGH
95 0 $repository->load($_->invoker, [$_], @filters);
96 }
97  
98 return
99 2 }
100  
101 0 ▶sub implements {
Subroutine implements: not called CC=1 SCAR=6.9
Pod documented
102 0 Froody::Error->throw("perl.methodcall.unimplemented",
103 "You must define an 'implements' method in '$_[0]'")
104 }
105  
106 # can is documented
107 # override 'can' so the invoker gets the right coderef
108 77 ▶sub can {
Subroutine can: called CC=3 SCAR=11.0
Pod undocumented
109 77 my $self = shift;
110 77 ▶ my $class = ref($self) ? ref($self) : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 77 0 77
111 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 77 my $map = \%{$class.'::FROODY_METHOD_MAPS'};
113 77 ▶ return $map->{$_[0]} if exists $map->{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$map{$_[0]} 2 75 77
114 # fallback
115 75 return $self->SUPER::can(@_);
116 }
117  
118 # MODIFY_CODE_ATTRIBUTES is documented
119 # in perldoc attributes
120  
121 2 ▶sub MODIFY_CODE_ATTRIBUTES {
Subroutine MODIFY_CODE_ATTRIBUTES: called CC=4 SCAR=14.0
122 2 my ($pkg, $code, @attr) = @_;
123 2 my @unwanted;
124 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
125 23 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 2 for my $attr (@attr) {
127 2 ▶ my ($name, $info) = $attr =~ m/^(\w+)\((.*)\)/
Branch: 1 branch
BranchTrueFalseTotal
() = $attr =~ /^(\w+)\((.*)\)/ or warn "unknown attribute $attr" 2 0 2
128 or warn "unknown attribute $attr";
129 2 ▶ if ($name eq 'FroodyMethod') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'FroodyMethod') { } 2 0 2
130 2 my $map = \%{$pkg.'::FROODY_METHOD_MAPS'};
131 2 $map->{$info} = $code;
132 }
133 else {
134 0 push @unwanted, $attr;
135 }
136 }
137 2 return @unwanted;
138 }
139  
140 23 1;
141  
142 __END__
« blib/lib/Froody/Server/Test.pm ↑ Summary blib/lib/Froody/Repository.pm »