Passing/DSL/Factory.pm

filter: Statementstmt 98.4% 65 / 66 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 6 / 15 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 6 totaltotal 77.2% 95 / 123 SCAR 25.2
CC
12
Cov
86%
make
12.7
set_error
2.1
BEGIN
1.0
CRAP 12.4
« Passing/Role/Script.pm ↑ Summary Passing/Role/ConnectionManager.pm »
1 package Message::Passing::DSL::Factory;
2 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use MooX::Types::MooseLike::Base qw/ HashRef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use String::RewritePrefix;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Message::Passing::Output::STDERR;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp qw/ confess /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Scalar::Util qw/ blessed /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Module::Runtime qw/ require_module /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use namespace::clean -except => [qw/ meta _build_default_error_chain /];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub expand_class_name {
12 13 ▶ my ($self, $type, $name) = @_;
Subroutine expand_class_name: called CC=1 SCAR=0.0
Pod undocumented
13 13 String::RewritePrefix->rewrite({
14 '' => 'Message::Passing::' . $type . '::',
15 '+' => ''
16 }, $name);
17 }
18  
19 has registry => (
20 is => 'ro',
21 isa => HashRef,
22 3 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 4 lazy => 1,
24 clearer => 'clear_registry',
25 );
26  
27 9 ▶sub registry_get { shift->registry->{shift()} }
Subroutine registry_get: called CC=1 SCAR=0.0
Pod undocumented
28 13 ▶sub registry_has { exists shift->registry->{shift()} }
Subroutine registry_has: called CC=1 SCAR=0.0
Pod undocumented
29 sub registry_set {
30 13 ▶ my ($self, $name, $val) = @_;
Subroutine registry_set: called CC=1 SCAR=0.0
Pod undocumented
31 13 $self->registry->{$name} = $val;
32 }
33  
34 sub set_error {
35 1 ▶ my ($self, %opts) = @_;
Subroutine set_error: called CC=2 SCAR=7.4
Pod undocumented
36 my $class = delete $opts{class}
37 1 ▶ || confess("Class name needed");
Condition33%1/3
delete $opts{'class'} || confess('Class name needed')
l!l&&r!l&&!r
100
MC/DC0%0/2
delete $opts{'class'} || confess('Class name needed')
delete $opts{'class'} confess('Class name needed')
Truth table33%1/3
A || B
A= delete $opts{'class'}B= confess('Class name needed')
ABresult
1X1
011
000
38 1 require_module($class);
39 1 $self->_set_error($class->new(%opts));
40 }
41  
42 4 ▶use Message::Passing::Role::HasErrorChain;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 *_build_default_error_chain = \&Message::Passing::Role::HasErrorChain::_build_default_error_chain;
44 4 has error => (
45 is => 'ro',
46 writer => '_set_error',
47 lazy => 1,
48 builder => '_build_default_error_chain',
49 );
50  
51 sub make {
52 13 ▶ my ($self, %opts) = @_;
Subroutine make: called CC=11 SCAR=25.4
Pod undocumented
53 my $class = delete $opts{class}
54 13 ▶ || confess("Class name needed");
Condition33%1/3
delete $opts{'class'} || confess('Class name needed')
l!l&&r!l&&!r
1300
MC/DC0%0/2
delete $opts{'class'} || confess('Class name needed')
delete $opts{'class'} confess('Class name needed')
Truth table33%1/3
A || B
A= delete $opts{'class'}B= confess('Class name needed')
ABresult
1X1
011
000
55 13 my $name = delete $opts{name};
56 13 my $type = delete $opts{_type};
57 13 ▶ confess("We already have a thing named $name")
Branch: 1 branch
BranchTrueFalseTotal
if $self->registry_has($name) 0 13 13
58 if $self->registry_has($name);
59 13 my $output_to = $opts{output_to};
60 13 ▶ if ($output_to && !blessed($output_to)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output_to and not builtin::blessed($output_to)) 9 4 13
Condition66%2/3
$output_to and not builtin::blessed($output_to)
!ll&&!rl&&r
409
MC/DC50%1/2
$output_to and not builtin::blessed($output_to)
$output_to not builtin::blessed($output_to)
Truth table66%2/3
A and not(B)
A= $output_toB= not builtin::blessed($output_to)
ABresult
0X0
100
111
61 # We have to deal with the ARRAY case here for Filter::T
62 9 ▶ if (ref($output_to) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $output_to eq 'ARRAY') { } 1 8 9
63 1 my @out;
64 1 foreach my $name_or_thing (@$output_to) {
65 1 ▶ if (blessed($name_or_thing)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($name_or_thing)) { } 0 1 1
66 0 push(@out, $name_or_thing);
67 }
68 else {
69 1 ▶ my $thing = $self->registry_get($name_or_thing)
Condition33%1/3
$self->registry_get($name_or_thing) || confess("Do not have a component named '${name_or_thing}'")
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->registry_get($name_or_thing) || confess("Do not have a component named '${name_or_thing}'")
$self->registry_get($name_or_thing) confess("Do not have a component named '${name_or_thing}'")
Truth table33%1/3
A || B
A= $self->registry_get($name_or_thing)B= confess("Do not have a component named '${name_or_thing}'")
ABresult
1X1
011
000
70 || confess("Do not have a component named '$name_or_thing'");
71 1 push(@out, $thing);
72 }
73 }
74 1 $opts{output_to} = \@out;
75 }
76 else {
77 8 ▶ my $proper_output_to = $self->registry_get($output_to)
Condition33%1/3
$self->registry_get($output_to) || confess("Do not have a component named '${output_to}'")
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->registry_get($output_to) || confess("Do not have a component named '${output_to}'")
$self->registry_get($output_to) confess("Do not have a component named '${output_to}'")
Truth table33%1/3
A || B
A= $self->registry_get($output_to)B= confess("Do not have a component named '${output_to}'")
ABresult
1X1
011
000
78 || confess("Do not have a component named '$output_to'");
79 8 $opts{output_to} = $proper_output_to;
80 }
81 }
82 13 ▶ if (!exists($opts{error})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"error"}) 13 0 13
83 13 $opts{error} = $self->error;
84 }
85 13 $class = $self->expand_class_name($type, $class);
86 13 require_module($class);
87 13 my $out = $class->new(%opts);
88 13 $self->registry_set($name, $out);
89 13 return $out;
90 }
91  
92  
93 4 1;
94  
95 =head1 NAME
96  
97 Message::Passing::DSL::Factory - Build a set of chains using symbolic names
98  
99 =head1 DESCRIPTION
100  
101 No user serviceable parts inside. See L<Message::Passing::DSL>.
102  
103 =head1 SPONSORSHIP
104  
105 This module exists due to the wonderful people at Suretec Systems Ltd.
106 <http://www.suretecsystems.com/> who sponsored its development for its
107 VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
108 the SureVoIP API -
109 <http://www.surevoip.co.uk/support/wiki/api_documentation>
110  
111 =head1 AUTHOR, COPYRIGHT AND LICENSE
112  
113 See L<Message::Passing>.
114  
115 =cut
116  
« Passing/Role/Script.pm ↑ Summary Passing/Role/ConnectionManager.pm »