« lib/Monitoring/Spooler/Transport/Smstrade.pm
↑ Summary
lib/Monitoring/Spooler/Transport/Sipgate.pm »
| 1 | package Monitoring::Spooler::Cmd::Command::bootstrap; | ||
| 2 | $Monitoring::Spooler::Cmd::Command::bootstrap::VERSION = '0.05'; | ||
| 3 | BEGIN { | ||
| 4 | $Monitoring::Spooler::Cmd::Command::bootstrap::AUTHORITY = 'cpan:TEX'; | ||
| 5 | } | ||
| 6 | # ABSTRACT: initializes a new installation | ||
| 7 | |||
| 8 | use 5.010_000; | ||
| 9 | use mro 'c3'; | ||
| 10 | use feature ':5.10'; | ||
| 11 | |||
| 12 | use Moose; | ||
| 13 | use namespace::autoclean; | ||
| 14 | |||
| 15 | # use IO::Handle; | ||
| 16 | # use autodie; | ||
| 17 | # use MooseX::Params::Validate; | ||
| 18 | # use Carp; | ||
| 19 | # use English qw( -no_match_vars ); | ||
| 20 | use Try::Tiny; | ||
| 21 | |||
| 22 | # extends ... | ||
| 23 | extends 'Monitoring::Spooler::Cmd::Command'; | ||
| 24 | # has ... | ||
| 25 | has 'name' => ( | ||
| 26 | 'is' => 'ro', | ||
| 27 | 'isa' => 'Str', | ||
| 28 | 'required' => 1, | ||
| 29 | 'traits' => [qw(Getopt)], | ||
| 30 | 'cmd_aliases' => 'n', | ||
| 31 | 'documentation' => 'Name of the new group', | ||
| 32 | ); | ||
| 33 | # with ... | ||
| 34 | # initializers ... | ||
| 35 | |||
| 36 | # your code here ... | ||
| 37 | sub execute { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | my $sql = 'SELECT COUNT(*) FROM groups'; | ||
| 41 | my $sth = $self->dbh()->prepexec($sql); | ||
| 42 | my $cnt = $sth->fetchrow_array(); | ||
| 43 | |||
| 44 | if($cnt > 0) { | ||
| 45 | print "You can not use this command once there is already at least one group\n"; | ||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | $sql = 'INSERT INTO groups (name) VALUES (?)'; | ||
| 50 | $sth = $self->dbh()->prepexec($sql,$self->name()); | ||
| 51 | if($sth) { | ||
| 52 | my $id = $self->dbh()->last_insert_id(undef, undef, undef, undef); | ||
| 53 | print "Created new group '".$self->name()."' with Id $id\n"; | ||
| 54 | } | ||
| 55 | |||
| 56 | return 1; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub abstract { | ||
| 60 | return "Initialize the database."; | ||
| 61 | } | ||
| 62 | |||
| 63 | no Moose; | ||
| 64 | __PACKAGE__->meta->make_immutable; | ||
| 65 | |||
| 66 | 1; | ||
| 67 | |||
| 68 | __END__ |