line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Base::Script; |
2
|
2
|
|
|
2
|
|
195080
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
44
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
70
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.07'; ## VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
App::Base::Script - A truly lazy person's tool for writing self-documenting, self-monitoring scripts |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package MyScript; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Moose; |
16
|
|
|
|
|
|
|
with 'App::Base::Script'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub documentation { return 'This is a script.'; } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub script_run { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
# do something |
23
|
|
|
|
|
|
|
return 0; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
no Moose; |
27
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package main; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
exit MyScript->new()->run(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
App::Base::Script builds on App::Base::Script::Common and provides common infrastructure that is |
36
|
|
|
|
|
|
|
useful for writing scripts. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 REQUIRED SUBCLASS METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
See also, L<App::Base::Script::Common> "REQUIRED METHODS" |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
2
|
|
856
|
use Moose::Role; |
|
2
|
|
|
|
|
609470
|
|
|
2
|
|
|
|
|
8
|
|
45
|
|
|
|
|
|
|
with 'App::Base::Script::Common'; |
46
|
2
|
|
|
2
|
|
7636
|
use Config; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
47
|
2
|
|
|
2
|
|
6
|
use Try::Tiny; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
332
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 script_run($self, @ARGS) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The code that actually executes the meat of the script. When a App::Base::Script is invoked |
52
|
|
|
|
|
|
|
by calling run(), all of the relevant options parsing and error handling is performed |
53
|
|
|
|
|
|
|
and then control is handed over to the script_run() method. The return value of script_run() |
54
|
|
|
|
|
|
|
is returned as the return value of run(). |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
requires 'script_run'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 The new() method |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
(See App::Base::Script::Common::new) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub __run { |
69
|
6
|
|
|
6
|
|
8
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
5
|
my $result; |
72
|
|
|
|
|
|
|
|
73
|
6
|
|
|
6
|
|
438
|
try { $result = $self->script_run(@{$self->parsed_args}); } |
|
6
|
|
|
|
|
184
|
|
74
|
|
|
|
|
|
|
catch { |
75
|
3
|
|
|
3
|
|
60
|
$self->error($_); |
76
|
6
|
|
|
|
|
94
|
}; |
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
1000411
|
return $result; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 error |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Handles errors generated by the script. This results in a call |
84
|
|
|
|
|
|
|
to App::Base::Script::Common::__error, which exits. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub error { |
89
|
5
|
|
|
5
|
1
|
106
|
my $self = shift; |
90
|
5
|
|
|
|
|
16
|
return $self->__error(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
2
|
|
32
|
no Moose::Role; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 USAGE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Invocation |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Invocation of a App::Base::Script-based script is accomplished as follows: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item - |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Define a class that implements the App::Base::Script interface (using 'with App::Base::Script') |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item - |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Instantiate an object of that class via new() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item - |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Run the script by calling run(). The return value of run() is the exit |
117
|
|
|
|
|
|
|
status of the script, and should typically be passed back to the calling |
118
|
|
|
|
|
|
|
program via exit() |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 Options handling |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
(See App::Base::Script::Common, "Options handling") |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Copyright (C) 2010-2014 Binary.com |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
131
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
132
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |