| 1 | #!/usr/bin/perl | ||||||||||||
| 2 | |||||||||||||
| 3 | package KiokuDB::Cmd::WithDSN::Create; | ||||||||||||
| 4 | 1 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 1 | with qw( | |||||||||||
| 11 | KiokuDB::Cmd::WithDSN | ||||||||||||
| 12 | KiokuDB::Cmd::TXN | ||||||||||||
| 13 | ); | ||||||||||||
| 14 | |||||||||||||
| 15 | 1 | requires "v"; | |||||||||||
| 16 | |||||||||||||
| 17 | 1 | has clear => ( | |||||||||||
| 18 | traits => [qw(Getopt)], | ||||||||||||
| 19 | isa => "Bool", | ||||||||||||
| 20 | is => "ro", | ||||||||||||
| 21 | cmd_aliases => "x", | ||||||||||||
| 22 | documentation => "clear the database before loading", | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | |||||||||||||
| 25 | 1 | has create => ( | |||||||||||
| 26 | traits => [qw(Getopt)], | ||||||||||||
| 27 | isa => "Bool", | ||||||||||||
| 28 | is => "ro", | ||||||||||||
| 29 | default => 1, | ||||||||||||
| 30 | cmd_aliases => "c", | ||||||||||||
| 31 | documentation => "create the database if it doesn't exist (defaults to true)", | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub _build_backend { | ||||||||||
|
Subroutine
_build_backend: not called CC=4 SCAR=30.0
| |||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | my $dsn = $self->dsn || croak("--dsn is required"); | ||||||||||
|
Condition0%0/2
$self->dsn || croak('--dsn is required')
MC/DC0%0/1
$self->dsn || croak('--dsn is required')
$self->dsn
Truth table0%0/2
A
A= $self->dsn
| |||||||||||||
| 38 | |||||||||||||
| 39 | 0 | $self->v("Connecting to DSN $dsn..."); | |||||||||||
| 40 | |||||||||||||
| 41 | 0 | require KiokuDB::Util; | |||||||||||
| 42 | 0 | my $b = KiokuDB::Util::dsn_to_backend( $dsn, create => $self->create ); | |||||||||||
| 43 | |||||||||||||
| 44 | 0 | $self->v(" $b\n"); | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | $self->try_txn_begin($b); | |||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | if ( $self->clear ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | ▶ | unless ( $b->does("KiokuDB::Backend::Role::Clear") ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 0 | croak "--clear specified but $b does not support clearing"; | |||||||||||
| 51 | |||||||||||||
| 52 | } | ||||||||||||
| 53 | 0 | $self->v("clearing database...."); | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | $b->clear; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | $self->v(" done\n"); | |||||||||||
| 58 | |||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 0 | $b; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 1 | __PACKAGE__ | |||||||||||
| 65 | |||||||||||||
| 66 | __END__ | ||||||||||||