lib/App/Standby/Cmd/Command/bootstrap.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 84.8% 56 / 66 CC 4 SCAR 7.2
CC
4
Cov
86%
execute
4.4
abstract
2.0
BEGIN
1.0
CRAP 2.1
« lib/App/Standby/Service/Pingdom.pm ↑ Summary script/standby-mgm-cgi.pl »
1 package App::Standby::Cmd::Command::bootstrap;
2 4 $App::Standby::Cmd::Command::bootstrap::VERSION = '0.04';
3 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 $App::Standby::Cmd::Command::bootstrap::AUTHORITY = 'cpan:TEX';
5 }
6 # ABSTRACT: Command to intialize the database
7  
8 4 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # use IO::Handle;
16 # use autodie;
17 # use MooseX::Params::Validate;
18 # use Carp;
19 # use English qw( -no_match_vars );
20 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Data::Pwgen;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # extends ...
24 4 extends 'App::Standby::Cmd::Command';
25 # has ...
26 4 has 'name' => (
27 'is' => 'ro',
28 'isa' => 'Str',
29 'required' => 1,
30 'traits' => [qw(Getopt)],
31 'cmd_aliases' => 'n',
32 'documentation' => 'Name of the new group',
33 );
34  
35 4 has 'key' => (
36 'is' => 'ro',
37 'isa' => 'Str',
38 'required' => 0,
39 'traits' => [qw(Getopt)],
40 'cmd_aliases' => 'k',
41 'documentation' => 'Key of the new group',
42 );
43 # with ...
44 # initializers ...
45  
46 # your code here ...
47 2 ▶sub execute {
Subroutine execute: called CC=4 SCAR=14.9
Pod documented
48 2 my $self = shift;
49  
50 2 my $sql = 'SELECT COUNT(*) FROM groups';
51 2 my $sth = $self->dbh()->prepexec($sql);
52 2 my $cnt = $sth->fetchrow_array();
53  
54 2 ▶ if($cnt > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt > 0) 0 2 2
55 0 print "You can not use this command once there is already at least one group\n";
56 0 return;
57 }
58  
59 2 ▶ my $key = $self->key() || Data::Pwgen::pwgen(16);
Condition33%1/3
$self->key || Data::Pwgen::pwgen(16)
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->key || Data::Pwgen::pwgen(16)
$self->key Data::Pwgen::pwgen(16)
Truth table33%1/3
A || B
A= $self->keyB= Data::Pwgen::pwgen(16)
ABresult
1X1
011
000
60  
61 2 $sql = 'INSERT INTO groups (name,key) VALUES (?,?)';
62 2 $sth = $self->dbh()->prepexec($sql,$self->name(),$key);
63 2 ▶ if($sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 2 0 2
64 2 print "Created new group '".$self->name()."' with key '".$key."'\n";
65 }
66  
67 2 return 1;
68 }
69  
70 0 ▶sub abstract {
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
71 0 return 'Initialize the database';
72 }
73  
74 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 4 __PACKAGE__->meta->make_immutable;
76  
77 4 1;
78  
79 __END__
80  
81 =pod
82  
83 =encoding utf-8
84  
85 =head1 NAME
86  
87 App::Standby::Cmd::Command::bootstrap - Command to intialize the database
88  
89 =head1 DESCRIPTION
90  
91 This class implements a command initialize the database.
92  
93 =head1 METHODS
94  
95 =head2 execute
96  
97 Run the bootstrap command
98  
99 =head2 abstract
100  
101 Workaround
102  
103 =head1 NAME
104  
105 App::Standby::Cmd::Command::bootstrap - Command to intialize the database
106  
107 =head1 AUTHOR
108  
109 Dominik Schulz <dominik.schulz@gauner.org>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2012 by Dominik Schulz.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
« lib/App/Standby/Service/Pingdom.pm ↑ Summary script/standby-mgm-cgi.pl »