| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package KiokuDB::Cmd::WithDSN::Write; | ||
| 4 | use Moose::Role; | ||
| 5 | |||
| 6 | use Carp qw(croak); | ||
| 7 | |||
| 8 | use namespace::clean -except => 'meta'; | ||
| 9 | |||
| 10 | with qw( | ||
| 11 | KiokuDB::Cmd::WithDSN | ||
| 12 | KiokuDB::Cmd::TXN | ||
| 13 | ); | ||
| 14 | |||
| 15 | requires "v"; | ||
| 16 | |||
| 17 | has dry_run => ( | ||
| 18 | traits => [qw(Getopt)], | ||
| 19 | isa => "Bool", | ||
| 20 | is => "ro", | ||
| 21 | cmd_flag => "dry-run", | ||
| 22 | cmd_aliases => "n", | ||
| 23 | documentation => "don't modify the database", | ||
| 24 | ); | ||
| 25 | |||
| 26 | sub _build_backend { | ||
| 27 | my $self = shift; | ||
| 28 | |||
| 29 | my $dsn = $self->dsn || croak("--dsn is required"); | ||
| 30 | |||
| 31 | $self->v("Connecting to DSN $dsn..."); | ||
| 32 | |||
| 33 | require KiokuDB::Util; | ||
| 34 | |||
| 35 | my $b = KiokuDB::Util::dsn_to_backend( $dsn, $self->dry_run ? ( readonly => 1 ) : () ); | ||
| 36 | |||
| 37 | $self->v(" $b\n"); | ||
| 38 | |||
| 39 | $self->try_txn_begin($b); | ||
| 40 | |||
| 41 | $b; | ||
| 42 | } | ||
| 43 | |||
| 44 | __PACKAGE__ | ||
| 45 | |||
| 46 | __END__ |