File Coverage

lib/Web/Components/Role.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             package Web::Components::Role;
2              
3 1     1   1902 use namespace::autoclean;
  1         2  
  1         15  
4              
5 1     1   115 use Web::Components::Util qw( deref );
  1         3  
  1         17  
6 1     1   311 use Web::ComposableRequest::Constants qw( TRUE );
  1         3  
  1         15  
7 1         22 use Unexpected::Types qw( HashRef NonEmptySimpleStr
8 1     1   306 NonNumericSimpleStr Object );
  1         3  
9 1     1   1657 use Moo::Role;
  1         3  
  1         11  
10              
11             has 'components' => is => 'ro', isa => HashRef, default => sub { {} },
12             weak_ref => TRUE;
13              
14             has 'config' => is => 'ro', isa => Object | HashRef, required => TRUE;
15              
16             has 'encoding' => is => 'lazy', isa => NonEmptySimpleStr,
17 1     1   56 builder => sub { deref $_[ 0 ]->config, 'encoding' };
18              
19             has 'log' => is => 'ro', isa => Object, required => TRUE;
20              
21             has 'moniker' => is => 'ro', isa => NonNumericSimpleStr, required => TRUE;
22              
23             around 'BUILDARGS' => sub {
24             my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args ); my $app;
25              
26             (exists $attr->{application} and $app = $attr->{application})
27             or return $attr;
28              
29             $app->can( 'config' ) and $attr->{config} //= $app->config;
30             $app->can( 'log' ) and $attr->{log } //= $app->log;
31              
32             return $attr;
33             };
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding utf-8
42              
43             =head1 Name
44              
45             Web::Components::Role - Attributes used when instantiating a Web::Components object
46              
47             =head1 Synopsis
48              
49             use Moo;
50              
51             with 'Web::Components::Role';
52              
53             =head1 Description
54              
55             Attributes used when instantiating a Web::Components object
56              
57             =head1 Configuration and Environment
58              
59             Defines the following attributes;
60              
61             =over 3
62              
63             =item C<components>
64              
65             A hash reference of component object references. This is not fully populated
66             until all of the components have been loaded. It can be used by components to
67             discover other dependant components
68              
69             =item C<config>
70              
71             A required object or hash reference
72              
73             =item C<encoding>
74              
75             A non empty simple string that defaults to the value of the configuration
76             attribute of the same name. Used to set input and output decoding / encoding
77              
78             =item C<log>
79              
80             A required object reference of type C<Logger>. The log object should support
81             the C<log> call as well as the usual log level calls
82              
83             =item C<moniker>
84              
85             A required non numeric simple string. This is the component name. It is used
86             to uniquely identify a component in the component collections held by the role
87             L<Web::Components::Loader>
88              
89             =back
90              
91             =head1 Subroutines/Methods
92              
93             =head2 C<BUILDARGS>
94              
95             If supplied with an object reference called C<application> the C<config> and
96             C<log> attribute values will be set from it if they are otherwise undefined
97              
98             =head1 Diagnostics
99              
100             None
101              
102             =head1 Dependencies
103              
104             =over 3
105              
106             =item L<Moo>
107              
108             =item L<Web::ComposableRequest>
109              
110             =item L<Unexpected>
111              
112             =back
113              
114             =head1 Incompatibilities
115              
116             There are no known incompatibilities in this module
117              
118             =head1 Bugs and Limitations
119              
120             There are no known bugs in this module. Please report problems to
121             http://rt.cpan.org/NoAuth/Bugs.html?Dist=Web-Components.
122             Patches are welcome
123              
124             =head1 Acknowledgements
125              
126             Larry Wall - For the Perl programming language
127              
128             =head1 Author
129              
130             Peter Flanigan, C<< <pjfl@cpan.org> >>
131              
132             =head1 License and Copyright
133              
134             Copyright (c) 2016 Peter Flanigan. All rights reserved
135              
136             This program is free software; you can redistribute it and/or modify it
137             under the same terms as Perl itself. See L<perlartistic>
138              
139             This program is distributed in the hope that it will be useful,
140             but WITHOUT WARRANTY; without even the implied warranty of
141             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
142              
143             =cut
144              
145             # Local Variables:
146             # mode: perl
147             # tab-width: 3
148             # End:
149             # vim: expandtab shiftwidth=3: