File Coverage

lib/Class/Usul.pm
Criterion Covered Total %
statement 26 28 92.8
branch 0 2 0.0
condition n/a
subroutine 12 14 85.7
pod 1 1 100.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package Class::Usul;
2              
3 20     20   122598 use 5.010001;
  20         73  
4 20     20   863 use namespace::autoclean;
  20         25422  
  20         115  
5 20     20   1286 use version; our $VERSION = qv( sprintf '0.83.%d', q$Rev: 1 $ =~ /\d+/gmx );
  20         44  
  20         142  
6              
7 20     20   3515 use Class::Usul::Constants qw( FALSE TRUE );
  20         47  
  20         164  
8 20     20   15163 use Class::Usul::Functions qw( data_dumper ns_environment );
  20         47  
  20         134  
9 20         257 use Class::Usul::Types qw( Bool ConfigProvider HashRef
10 20     20   28210 Localiser LoadableClass Locker Logger );
  20         83  
11 20     20   36141 use Moo;
  20         44  
  20         203  
12              
13             # Attribute constructors
14             my $_build_debug = sub {
15 0 0   0   0 return !!ns_environment( $_[ 0 ]->config->appclass, 'debug' ) ? TRUE : FALSE;
16             };
17              
18             # Public attributes
19             has 'config' => is => 'lazy', isa => ConfigProvider,
20 23     23   686 builder => sub { $_[ 0 ]->config_class->new( $_[ 0 ]->_config_attr)},
21             init_arg => undef;
22              
23 0     0   0 has '_config_attr' => is => 'ro', isa => HashRef, builder => sub { {} },
24             init_arg => 'config';
25              
26             has 'config_class' => is => 'ro', isa => LoadableClass, coerce => TRUE,
27             default => 'Class::Usul::Config';
28              
29             has 'debug' => is => 'lazy', isa => Bool, builder => $_build_debug;
30              
31             has 'l10n' => is => 'lazy', isa => Localiser,
32 4     4   655 builder => sub { $_[ 0 ]->l10n_class->new( builder => $_[ 0 ] ) },
33             handles => [ 'loc', 'localize' ];
34              
35             has 'l10n_class' => is => 'lazy', isa => LoadableClass, coerce => TRUE,
36             default => 'Class::Usul::L10N';
37              
38             has 'lock' => is => 'lazy', isa => Locker,
39 6     6   272 builder => sub { $_[ 0 ]->lock_class->new( builder => $_[ 0 ] ) };
40              
41             has 'lock_class' => is => 'lazy', isa => LoadableClass, coerce => TRUE,
42             default => 'IPC::SRLock';
43              
44             has 'log' => is => 'lazy', isa => Logger,
45 6     6   1037 builder => sub { $_[ 0 ]->log_class->new( builder => $_[ 0 ] ) };
46              
47             has 'log_class' => is => 'lazy', isa => LoadableClass, coerce => TRUE,
48             default => 'Class::Usul::Log';
49              
50             # Public methods
51             sub dumper { # Damm handy for development
52 2     2 1 23 my $self = shift; return data_dumper( @_ );
  2         11  
53             }
54              
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =encoding utf-8
62              
63             =begin html
64              
65             <a href="https://travis-ci.org/pjfl/p5-class-usul"><img src="https://travis-ci.org/pjfl/p5-class-usul.svg?branch=master" alt="Travis CI Badge"></a>
66             <a href="http://badge.fury.io/pl/Class-Usul"><img src="https://badge.fury.io/pl/Class-Usul.svg" alt="CPAN Badge"></a>
67             <a href="http://cpants.cpanauthors.org/dist/Class-Usul"><img src="http://cpants.cpanauthors.org/dist/Class-Usul.png" alt="Kwalitee Badge"></a>
68              
69             =end html
70              
71             =head1 Name
72              
73             Class::Usul - A base class providing config, locking, logging, and l10n
74              
75             =head1 Version
76              
77             Describes Class::Usul version v0.83.$Rev: 1 $
78              
79             =head1 Synopsis
80              
81             use Class::Usul;
82             use Class::Usul::Constants qw( FALSE );
83             use Class::Usul::Functions qw( find_apphome get_cfgfiles );
84              
85             my $attr = { config => {} }; my $conf = $attr->{config};
86              
87             $conf->{appclass } or die "Application class not specified";
88             $attr->{config_class} //= $conf->{appclass}.'::Config';
89             $conf->{home } = find_apphome $conf->{appclass};
90             $conf->{cfgfiles } = get_cfgfiles $conf->{appclass}, $conf->{home};
91              
92             return Class::Usul->new( $attr );
93              
94             =head1 Description
95              
96             These modules provide a set of base classes for Perl modules and
97             applications. It provides configuration file loading
98             L<Class::Usul::Config>, locking to single thread processes
99             L<IPC::SRLock>, logging L<Class::Usul::Log> and localisation
100             L<Class::Usul::L10N>
101              
102             The class L<Class::Usul::Programs> is a base class for command line interfaces
103              
104             Interprocess communication is handled by L<Class::Usul::IPC>
105              
106             L<Class::Usul::File> makes the functionality of L<File::DataClass> available
107              
108             =head1 Configuration and Environment
109              
110             Defines the following attributes;
111              
112             =over 3
113              
114             =item C<config>
115              
116             The C<config> attribute should be a hash reference that may define key / value
117             pairs that provide filesystem paths for the temporary directory etc.
118              
119             =item C<config_class>
120              
121             Defaults to L<Class::Usul::Config> and is of type C<LoadableClass>. An
122             instance of this class is loaded and instantiated using the hash reference
123             in the C<config> attribute. It provides accessor methods with symbol
124             inflation and smart defaults. Add configuration attributes by
125             subclassing this class
126              
127             =item C<debug>
128              
129             A boolean which defaults to false. Usually an instance of this class is passed
130             into the constructors of other classes which set their own debug state to this
131             value
132              
133             =item C<l10n>
134              
135             A lazily evaluated instance of the C<l10n_class>. This object reference is a
136             L<Localiser|Class::Usul::Types/Localiser> which handles the C<localize> method
137              
138             =item C<l10n_class>
139              
140             A lazy loadable class which defaults to L<Class::Usul::L10N>
141              
142             =item C<lock>
143              
144             A lazily evaluated instance of the C<lock_class>. This object reference is a
145             L<Locker|Class::Usul::Types/Locker>
146              
147             =item C<lock_class>
148              
149             A lazy loadable class which defaults to L<IPC::SRLock>
150              
151             =item C<log>
152              
153             A lazily evaluated instance of the C<log_class>. This object reference is a
154             L<Logger|Class::Usul::Types/Logger>
155              
156             =item C<log_class>
157              
158             A lazy loadable class which defaults to L<Class::Usul::Log>
159              
160             =back
161              
162             =head1 Subroutines/Methods
163              
164             =head2 C<dumper>
165              
166             $self->dumper( $some_var );
167              
168             Use L<Data::Printer> to dump arguments for development purposes
169              
170             =head1 Diagnostics
171              
172             Setting the I<debug> attribute to true causes messages to be logged at the
173             debug level
174              
175             =head1 Dependencies
176              
177             =over 3
178              
179             =item L<Class::Usul::Config>
180              
181             =item L<Class::Usul::Constants>
182              
183             =item L<Class::Usul::Functions>
184              
185             =item L<Class::Usul::L10N>
186              
187             =item L<Class::Usul::Log>
188              
189             =item L<Class::Usul::Types>
190              
191             =item L<IPC::SRLock>
192              
193             =item L<Moo>
194              
195             =back
196              
197             =head1 Incompatibilities
198              
199             There are no known incompatibilities in this module
200              
201             =head1 Bugs and Limitations
202              
203             There are no known bugs in this module. Please report problems to
204             http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Usul. Patches are
205             welcome
206              
207             =head1 Author
208              
209             Peter Flanigan, C<< <pjfl@cpan.org> >>
210              
211             =head1 Acknowledgements
212              
213             Larry Wall - For the Perl programming language
214              
215             =head1 License and Copyright
216              
217             Copyright (c) 2017 Peter Flanigan. All rights reserved
218              
219             This program is free software; you can redistribute it and/or modify it
220             under the same terms as Perl itself. See L<perlartistic>
221              
222             This program is distributed in the hope that it will be useful,
223             but WITHOUT WARRANTY; without even the implied warranty of
224             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
225              
226             =cut
227              
228             # Local Variables:
229             # mode: perl
230             # tab-width: 3
231             # End: