line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Usul::Programs; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
1043713
|
use namespace::autoclean; |
|
18
|
|
|
|
|
218797
|
|
|
18
|
|
|
|
|
81
|
|
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
10335
|
use Class::Usul::Constants qw( TRUE ); |
|
18
|
|
|
|
|
66
|
|
|
18
|
|
|
|
|
121
|
|
6
|
18
|
|
|
18
|
|
16530
|
use Class::Usul::Functions qw( find_apphome get_cfgfiles ); |
|
18
|
|
|
|
|
52
|
|
|
18
|
|
|
|
|
224
|
|
7
|
18
|
|
|
18
|
|
28927
|
use File::DataClass::Types qw( Directory ); |
|
18
|
|
|
|
|
604402
|
|
|
18
|
|
|
|
|
233
|
|
8
|
18
|
|
|
18
|
|
17472
|
use Scalar::Util qw( blessed ); |
|
18
|
|
|
|
|
51
|
|
|
18
|
|
|
|
|
1002
|
|
9
|
18
|
|
|
18
|
|
95
|
use Moo; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
143
|
|
10
|
18
|
|
|
18
|
|
12969
|
use Class::Usul::Options; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
111
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
extends q(Class::Usul); |
13
|
|
|
|
|
|
|
with q(Class::Usul::TraitFor::OutputLogging); |
14
|
|
|
|
|
|
|
with q(Class::Usul::TraitFor::Prompting); |
15
|
|
|
|
|
|
|
with q(Class::Usul::TraitFor::DebugFlag); |
16
|
|
|
|
|
|
|
with q(Class::Usul::TraitFor::Usage); |
17
|
|
|
|
|
|
|
with q(Class::Usul::TraitFor::RunningMethods); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Override attribute default in base class |
20
|
|
|
|
|
|
|
has '+config_class' => default => 'Class::Usul::Config::Programs'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Public attributes |
23
|
|
|
|
|
|
|
option 'home' => is => 'lazy', isa => Directory, format => 's', |
24
|
|
|
|
|
|
|
documentation => 'Directory containing the configuration file', |
25
|
0
|
|
|
0
|
|
|
builder => sub { $_[ 0 ]->config->home }, coerce => TRUE; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Construction |
28
|
|
|
|
|
|
|
around 'BUILDARGS' => sub { |
29
|
|
|
|
|
|
|
my ($orig, $self, @args) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $attr = $orig->( $self, @args ); my $conf = $attr->{config} //= {}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $appclass = delete $attr->{appclass}; my $home = delete $attr->{home}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$conf->{appclass} //= $appclass || blessed $self || $self; |
36
|
|
|
|
|
|
|
$conf->{home } //= find_apphome $conf->{appclass}, $home; |
37
|
|
|
|
|
|
|
$conf->{cfgfiles} //= get_cfgfiles $conf->{appclass}, $conf->{home}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $attr; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub BUILD {} # Modified by applied roles |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding utf8 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 Name |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Class::Usul::Programs - Re-composable support for command line programs |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 Synopsis |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# In YourClass.pm |
59
|
|
|
|
|
|
|
use Moo; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
extends q(Class::Usul::Programs); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# In yourProg.pl |
64
|
|
|
|
|
|
|
use YourClass; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
exit YourClass->new_with_options( appclass => 'YourApplicationClass' )->run; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 Description |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This base class provides methods common to command line programs. The |
71
|
|
|
|
|
|
|
constructor can initialise a multi-lingual message catalogue if required |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 Configuration and Environment |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Supports this list of command line options: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=over 3 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C<home> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Directory containing the configuration file |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Defines these attributes; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over 3 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item C<config_class> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Overrides the default in the base class, setting it to |
92
|
|
|
|
|
|
|
C<Class::Usul::Config::Programs> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 Subroutines/Methods |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 BUILDARGS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Called just before the object is constructed this method modifier determines |
101
|
|
|
|
|
|
|
the location of the configuration file |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 BUILD |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This empty subroutine exists to allow for modification by the applied roles |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 Diagnostics |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Turning debug on produces log output at the debug level |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 Dependencies |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over 3 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item L<Class::Usul::Options> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item L<Class::Usul::TraitFor::DebugFlag> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item L<Class::Usul::TraitFor::OutputLogging> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item L<Class::Usul::TraitFor::Prompting> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item L<Class::Usul::TraitFor::RunningMethods> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item L<Class::Usul::TraitFor::Usage> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item L<Moo> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 Incompatibilities |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
There are no known incompatibilities in this module |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 Bugs and Limitations |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
There are no known bugs in this module. Please report problems to |
138
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Usul. |
139
|
|
|
|
|
|
|
Patches are welcome |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 Author |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Peter Flanigan, C<< <pjfl@cpan.org> >> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 License and Copyright |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright (c) 2017 Peter Flanigan. All rights reserved |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
150
|
|
|
|
|
|
|
under the same terms as Perl itself. See L<perlartistic> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
153
|
|
|
|
|
|
|
but WITHOUT WARRANTY; without even the implied warranty of |
154
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Local Variables: |
159
|
|
|
|
|
|
|
# mode: perl |
160
|
|
|
|
|
|
|
# tab-width: 3 |
161
|
|
|
|
|
|
|
# End: |