| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::JESP::Cmd::CommandJESP; |
|
2
|
|
|
|
|
|
|
$App::JESP::Cmd::CommandJESP::VERSION = '0.016'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6255
|
use base qw/App::JESP::Cmd::Command/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
179
|
|
|
5
|
1
|
|
|
1
|
|
10
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
53
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use App::JESP; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Log::Any qw/$log/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
App::JESP::Cmd::CommandJESP - Superclass for commands in need of a App::JESP instance. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 opt_spec |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Common options for App::JESP based commands. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub opt_spec { |
|
23
|
0
|
|
|
0
|
1
|
|
my ( $class, $app ) = @_; |
|
24
|
|
|
|
|
|
|
return ( |
|
25
|
0
|
|
|
|
|
|
[ 'home=s' => |
|
26
|
|
|
|
|
|
|
"The home directory where the plan.json lives" ], |
|
27
|
|
|
|
|
|
|
[ 'dsn=s' => |
|
28
|
|
|
|
|
|
|
"The DSN to connect to the DB. See https://metacpan.org/pod/DBI#parse_dsn for DSN format" |
|
29
|
|
|
|
|
|
|
."\nExamples:\n" |
|
30
|
|
|
|
|
|
|
."\n dbi:mysql:database=testdb;host=localhost;port=3306" |
|
31
|
|
|
|
|
|
|
."\n dbi:SQLite:dbname=demo/test.db" |
|
32
|
|
|
|
|
|
|
."\n dbi:Pg:dbname=testdb;host=localhost;port=5432" |
|
33
|
|
|
|
|
|
|
."\n" |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
], |
|
36
|
|
|
|
|
|
|
[ 'username=s' => |
|
37
|
|
|
|
|
|
|
"The username to connect to the DB", { default => undef } ], |
|
38
|
|
|
|
|
|
|
[ 'password=s' => |
|
39
|
|
|
|
|
|
|
"The password to connect to the DB", { default => undef } ], |
|
40
|
|
|
|
|
|
|
[ 'prefix=s' => |
|
41
|
|
|
|
|
|
|
"The prefix for all jesp metatables. Defaults to 'jesp_'" ], |
|
42
|
|
|
|
|
|
|
$class->options($app), |
|
43
|
|
|
|
|
|
|
) |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 options |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Override this in subclasses to add options to opt_spec |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
0
|
1
|
|
sub options{return ();} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 validate_args |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Do some stuff with validate args. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub validate_args { |
|
61
|
0
|
|
|
0
|
1
|
|
my ( $self, $opts, $args ) = @_; |
|
62
|
0
|
0
|
|
|
|
|
unless( $opts->dsn() ){ die "Missing 'dsn' option. Run with -h\n"; } |
|
|
0
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
unless( $opts->home() ){ die "Missing 'home' option. Run with -h\n"; } |
|
|
0
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Time to build the JESP |
|
66
|
0
|
|
|
|
|
|
$log->debug("Building App::JESP instance"); |
|
67
|
0
|
0
|
|
|
|
|
my $jesp = App::JESP->new({ |
|
|
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
dsn => $opts->dsn(), |
|
69
|
|
|
|
|
|
|
home => $opts->home(), |
|
70
|
|
|
|
|
|
|
( $opts->username() ? ( username => $opts->username() ) : ( username => undef ) ), |
|
71
|
|
|
|
|
|
|
( $opts->password() ? ( password => $opts->password() ) : ( password => undef ) ), |
|
72
|
|
|
|
|
|
|
}); |
|
73
|
0
|
|
|
|
|
|
$log->debug("App::JESP instance built"); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Inject __jesp in myself. |
|
76
|
|
|
|
|
|
|
# Yes this is a bit dirty, but it works. |
|
77
|
0
|
|
|
|
|
|
$self->{__jesp} = $jesp; |
|
78
|
0
|
|
|
|
|
|
$self->validate( $opts, $args ); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 validate |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Override that in subclasses to validate further. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
0
|
1
|
|
sub validate{}; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 jesp |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns the current JESP instance. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub jesp{ |
|
96
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
97
|
0
|
|
|
|
|
|
return $self->{__jesp}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |