Run/Base/Plugger.pm

filter: Statementstmt 100% 52 / 52 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 100% 70 / 70 CC 4 SCAR 6.2
CC
4
Cov
100%
_update_ISA
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Run/Straps/EventWrapper.pm ↑ Summary Run/Output.pm »
1 package Test::Run::Base::Plugger;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 19 extends ("Test::Run::Base");
11  
12 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 19 require UNIVERSAL::require;
15  
16 =head1 NAME
17  
18 Test::Run::Base::Plugger - an object class with plug-ins.
19  
20 =head1 DESCRIPTION
21  
22 This is a class that abstracts an object class with plugins.
23  
24 =head1 METHODS
25  
26 =cut
27  
28 19 has '_base' => (is => "rw", isa => "Str", init_arg => "base", );
29 19 has '_into' => (is => "rw", isa => "Str", init_arg => "into", );
30 has '_plugins' => (is => "rw", isa => "ArrayRef",
31 205 ▶ default => sub { []; }, lazy => 1
Subroutine __ANON__: called CC=1 SCAR=0.0
32 );
33  
34 =head2 $plugger = Test::Run::Base::Plugger->new({base => $base, into => $into})
35  
36 $base is the base class and $into is the namespace to put everything into.
37  
38 =head2 BUILD
39  
40 For Moose.
41  
42 =cut
43  
44 sub BUILD
45 205 ▶{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
46 205 my $self = shift;
47  
48 205 $self->_update_ISA();
49  
50 204 return;
51 }
52  
53 sub _update_ISA
54 409 ▶{
Subroutine _update_ISA: called CC=4 SCAR=13.9
55 409 my $self = shift;
56  
57 409 my $base_class = $self->_base();
58 409 my $into_class = $self->_into();
59  
60 19 ▶ my $isa_ref = do { no strict 'refs'; \@{"${into_class}::ISA"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 409 @$isa_ref = ();
63  
64 409 foreach my $plugin (@{$self->_plugins()})
65 {
66 5 ▶ if (!$plugin->require())
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin->require) 1 4 5
67 {
68 1 die $@;
69 }
70 4 push @$isa_ref, $plugin;
71 }
72  
73 408 ▶ if (!$base_class->require())
Branch: 1 branch
BranchTrueFalseTotal
unless ($base_class->require) 1 407 408
74 {
75 1 die $@;
76 }
77  
78 407 push @$isa_ref, $base_class;
79  
80 407 return;
81 }
82  
83 =head2 $plugger->add_plugins(\@plugins)
84  
85 Adds @plugins to the list of plugins used by the $into module.
86  
87 =cut
88  
89 sub add_plugins
90 204 ▶{
Subroutine add_plugins: called CC=1 SCAR=0.0
Pod documented
91 204 my $self = shift;
92 204 my $more_plugins = shift;
93  
94 204 push @{$self->_plugins()}, @{$more_plugins};
95  
96 204 $self->_update_ISA();
97 }
98  
99 =head2 $pluggin->create_new(@args)
100  
101 Constructs a new instance of $into.
102  
103 =cut
104  
105 sub create_new
106 203 ▶{
Subroutine create_new: called CC=1 SCAR=0.0
Pod documented
107 203 my $self = shift;
108  
109 203 return $self->_into()->new(@_);
110 }
111  
112 =head1 LICENSE
113  
114 This file is freely distributable under the MIT X11 license.
115  
116 L<http://www.opensource.org/licenses/mit-license.php>
117  
118 =head1 AUTHOR
119  
120 Shlomi Fish, L<http://www.shlomifish.org/>.
121  
122 =cut
123  
124 19 1;
125  
« Run/Straps/EventWrapper.pm ↑ Summary Run/Output.pm »