lib/Web/Components/Role.pm

filter: Statementstmt 96.7% 30 / 31 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 78.1% 43 / 55 CC 6 SCAR 13.6
CC
6
Cov
84%
__ANON__
7.1
__ANON__
2.0
BEGIN
1.0
CRAP 3.9
« lib/Web/Components/Util.pm ↑ Summary blib/lib/Web/Components/ReverseMap.pm »
1 package Web::Components::Role;
2  
3 1 ▶use Web::ComposableRequest::Constants qw( TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Unexpected::Types qw( HashRef NonEmptySimpleStr
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 NonNumericSimpleStr Object );
6 1 ▶use Web::Components::Util qw( deref );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =encoding utf-8
10  
11 =head1 Name
12  
13 Web::Components::Role - Attributes used when instantiating a Web::Components object
14  
15 =head1 Synopsis
16  
17 use Moo;
18  
19 with 'Web::Components::Role';
20  
21 =head1 Description
22  
23 Attributes used when instantiating a Web::Components object
24  
25 =head1 Configuration and Environment
26  
27 Defines the following attributes;
28  
29 =over 3
30  
31 =item C<components>
32  
33 A hash reference of component object references. This is not fully populated
34 until all of the components have been loaded. It can be used by components to
35 discover other dependant components
36  
37 =cut
38  
39 has 'components' =>
40 is => 'ro',
41 isa => HashRef,
42 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 1 weak_ref => TRUE;
44  
45 =item C<config>
46  
47 A required object or hash reference
48  
49 =cut
50  
51 1 has 'config' => is => 'ro', isa => Object | HashRef, required => TRUE;
52  
53 =item C<encoding>
54  
55 A non empty simple string that defaults to the value of the configuration
56 attribute of the same name. Used to set input and output decoding / encoding
57  
58 =cut
59  
60 has 'encoding' =>
61 is => 'lazy',
62 isa => NonEmptySimpleStr,
63 1 ▶ default => sub { deref $_[0]->config, 'encoding', 'UTF-8' };
Subroutine __ANON__: called CC=1 SCAR=0.0
64  
65 =item C<log>
66  
67 A required object reference of type C<Logger>. The log object should support
68 the C<log> call as well as the usual log level calls
69  
70 =cut
71  
72 1 has 'log' => is => 'ro', isa => Object, required => TRUE;
73  
74 =item C<moniker>
75  
76 A required non numeric simple string. This is the component name. It is used
77 to uniquely identify a component in the component collections held by the role
78 L<Web::Components::Loader>
79  
80 =cut
81  
82 1 has 'moniker' => is => 'ro', isa => NonNumericSimpleStr, required => TRUE;
83  
84 =back
85  
86 =head1 Subroutines/Methods
87  
88 =over 3
89  
90 =item C<BUILDARGS>
91  
92 If supplied with an object reference called C<application> the C<config> and
93 C<log> attribute values will be set from it if they are otherwise undefined
94  
95 =cut
96  
97 4 ▶around 'BUILDARGS' => sub {
Subroutine __ANON__: called CC=6 SCAR=19.6
98 4 my ($orig, $self, @args) = @_;
99  
100 4 my $attr = $orig->($self, @args);
101  
102 4 ▶ return $attr unless exists $attr->{application};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr->{"application"} 1 3 4
103  
104 3 my $app = $attr->{application};
105  
106 3 ▶ $attr->{config} //= $app->config if $app->can('config');
Branch: 1 branch
BranchTrueFalseTotal
if $app->can("config") 3 0 3
Condition33%1/3
$attr->{"config"} //= $app->config
l!l&&r!l&&!r
030
MC/DC0%0/2
$attr->{"config"} //= $app->config
$attr->{"config"} $app->config
Truth table33%1/3
A //= B
A= $attr->{"config"}B= $app->config
ABresult
1X1
011
000
107 3 ▶ $attr->{log} //= $app->log if $app->can('log');
Branch: 1 branch
BranchTrueFalseTotal
if $app->can("log") 3 0 3
Condition33%1/3
$attr->{"log"} //= $app->log
l!l&&r!l&&!r
030
MC/DC0%0/2
$attr->{"log"} //= $app->log
$attr->{"log"} $app->log
Truth table33%1/3
A //= B
A= $attr->{"log"}B= $app->log
ABresult
1X1
011
000
108  
109 3 return $attr;
110 1 };
111  
112 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 1 1;
115  
116 __END__
« lib/Web/Components/Util.pm ↑ Summary blib/lib/Web/Components/ReverseMap.pm »