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