| 1 | package Dackup::Cache; | ||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | has 'filename' => ( | |||||||||
| 6 | is => 'ro', | ||||||||||
| 7 | isa => 'Path::Class::File', | ||||||||||
| 8 | required => 1, | ||||||||||
| 9 | ); | ||||||||||
| 10 | 1 | has 'dbh' => ( | |||||||||
| 11 | is => 'rw', | ||||||||||
| 12 | isa => 'DBI::db', | ||||||||||
| 13 | required => 0, | ||||||||||
| 14 | ); | ||||||||||
| 15 | 1 | has 'sth_select' => ( | |||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => 'DBI::st', | ||||||||||
| 18 | required => 0, | ||||||||||
| 19 | ); | ||||||||||
| 20 | 1 | has 'sth_insert' => ( | |||||||||
| 21 | is => 'rw', | ||||||||||
| 22 | isa => 'DBI::st', | ||||||||||
| 23 | required => 0, | ||||||||||
| 24 | ); | ||||||||||
| 25 | 1 | has 'sth_delete' => ( | |||||||||
| 26 | is => 'rw', | ||||||||||
| 27 | isa => 'DBI::st', | ||||||||||
| 28 | required => 0, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 34 | 1 | my $self = shift; | |||||||||
| 35 | 1 | my $filename = $self->filename; | |||||||||
| 36 | |||||||||||
| 37 | 1 | my $exists = -f $filename; | |||||||||
| 38 | |||||||||||
| 39 | 1 | my $dbh = DBI->connect( | |||||||||
| 40 | "dbi:SQLite:dbname=$filename", | ||||||||||
| 41 | "", "", | ||||||||||
| 42 | { RaiseError => 1, | ||||||||||
| 43 | AutoCommit => 1, | ||||||||||
| 44 | } | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | 1 | ▶ | unless ($exists) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | $dbh->do('PRAGMA auto_vacuum = 1'); | |||||||||
| 49 | 1 | $dbh->do( ' | |||||||||
| 50 | CREATE TABLE md5_hex ( | ||||||||||
| 51 | id varchar NOT NULL, | ||||||||||
| 52 | md5_hex char(32) NOT NULL, | ||||||||||
| 53 | PRIMARY KEY (id) | ||||||||||
| 54 | )' ); | ||||||||||
| 55 | } | ||||||||||
| 56 | 1 | $self->dbh($dbh); | |||||||||
| 57 | 1 | $self->sth_select( | |||||||||
| 58 | $dbh->prepare('SELECT md5_hex FROM md5_hex WHERE id = ?') ); | ||||||||||
| 59 | 1 | $self->sth_insert( $dbh->prepare('INSERT INTO md5_hex VALUES (?, ?)') ); | |||||||||
| 60 | 1 | $self->sth_delete( $dbh->prepare('DELETE FROM md5_hex WHERE id = ?') ); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 9 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | 9 | my ( $self, $id ) = @_; | |||||||||
| 65 | 9 | my $sth = $self->sth_select; | |||||||||
| 66 | 9 | $sth->execute($id); | |||||||||
| 67 | 9 | my ($md5_hex) = $sth->fetchrow_array; | |||||||||
| 68 | 9 | return $md5_hex; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 6 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 72 | 6 | my ( $self, $id, $md5_hex ) = @_; | |||||||||
| 73 | 6 | $self->sth_insert->execute( $id, $md5_hex ); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 77 | 0 | my ( $self, $id ) = @_; | |||||||||
| 78 | 0 | $self->sth_delete->execute($id); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | 1; | |||||||||