JESP/Cmd/CommandJESP.pm

filter: Statementstmt 53.1% 17 / 32 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 100% 5 / 5 totaltotal 49.0% 27 / 55 CC 5 SCAR 24.5
CC
5
Cov
42%
validate_args
30.0
opt_spec
2.0
options
2.0
CRAP 11.6
« JESP/Driver.pm ↑ Summary JESP.pm »
1 package App::JESP::Cmd::CommandJESP;
2 1 $App::JESP::Cmd::CommandJESP::VERSION = '0.016';
3  
4 1 ▶use base qw/App::JESP::Cmd::Command/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use App::JESP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Log::Any qw/$log/;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
23 0 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 ▶sub options{return ();}
Subroutine options: not called CC=1 SCAR=6.9
Pod documented
53  
54 =head2 validate_args
55  
56 Do some stuff with validate args.
57  
58 =cut
59  
60 0 ▶sub validate_args {
Subroutine validate_args: not called CC=5 SCAR=34.0
Pod documented
61 0 my ( $self, $opts, $args ) = @_;
62 0 ▶ unless( $opts->dsn() ){ die "Missing 'dsn' option. Run with -h\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->dsn) 0 0 0
63 0 ▶ unless( $opts->home() ){ die "Missing 'home' option. Run with -h\n"; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->home) 0 0 0
64  
65 # Time to build the JESP
66 0 $log->debug("Building App::JESP instance");
67 0 ▶ my $jesp = App::JESP->new({
Branch: 2 branches
BranchTrueFalseTotal
$opts->username ? : 0 0 0
$opts->password ? : 0 0 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 ▶sub validate{};
Subroutine validate: not called CC=1 SCAR=0.0
Pod documented
88  
89 =head2 jesp
90  
91 Returns the current JESP instance.
92  
93 =cut
94  
95 0 ▶sub jesp{
Subroutine jesp: not called CC=1 SCAR=6.9
Pod documented
96 0 my ($self) = @_;
97 0 return $self->{__jesp};
98 }
99  
100 1 1;
« JESP/Driver.pm ↑ Summary JESP.pm »