| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | DynGig::Automata::EZDB::Exclude - Extends DynGig::Util::EZDB. | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | =cut | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | package DynGig::Automata::EZDB::Exclude; | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base DynGig::Util::EZDB; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | =head1 SCHEMA | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | alpha INTEGER NOT NULL, | ||||||||||||||||||||||||||||||||||
| 17 | omega INTEGER NOT NULL, | ||||||||||||||||||||||||||||||||||
| 18 | key TEXT NOT NULL, | ||||||||||||||||||||||||||||||||||
| 19 | value TEXT, | ||||||||||||||||||||||||||||||||||
| 20 | PRIMARY KEY ( key ) | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||||||||
| 23 | sub new | ||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 25 | 0 | DynGig::Util::EZDB->schema | |||||||||||||||||||||||||||||||||
| 26 | ( | ||||||||||||||||||||||||||||||||||
| 27 | alpha => 'INTEGER NOT NULL', | ||||||||||||||||||||||||||||||||||
| 28 | omega => 'INTEGER NOT NULL', | ||||||||||||||||||||||||||||||||||
| 29 | key => 'TEXT NOT NULL PRIMARY KEY', | ||||||||||||||||||||||||||||||||||
| 30 | value => 'TEXT', | ||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 0 | bless DynGig::Util::EZDB::new( @_ ), __PACKAGE__; | |||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | See DynGig::Util::EZDB for other methods. | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | my $table = 'table1'; | ||||||||||||||||||||||||||||||||||
| 41 | my $start = time; | ||||||||||||||||||||||||||||||||||
| 42 | my $end = $start + 3600; | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | $db->set( $table, $start, $end, 'key1', 'value1' ); | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | $db->get( $table, time ); | ||||||||||||||||||||||||||||||||||
| 47 | $db->get( $table ); | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | $db->expire( $table, time ); | ||||||||||||||||||||||||||||||||||
| 50 | $db->expire( $table ); | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||||||||
| 53 | sub set ## enter a record into a table | ||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 0 | my ( $this, $table, $epoch, $period, $key, $value ) = @_; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | map { return unless _numeric( $_ ) } $epoch, $period; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return unless defined $key && ( $period += $epoch ) > time; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and ($period += $epoch) > time
MC/DC0%0/2
defined $key and ($period += $epoch) > time
defined $key
($period += $epoch) > time
Truth table0%0/3
A and B
A= defined $keyB= ($period += $epoch) > time
| |||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $value = '' if ! defined $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 0 | my @time = map { int $_ } $epoch, $period; | |||||||||||||||||||||||||||||||||
| 63 | 0 | my $result = $this->_execute( $table, 'insert', @time, $key, $value ); | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | sub get ## get active records from a table | ||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 68 | 0 | my ( $this, $table, $epoch ) = @_; | |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $epoch = _numeric( $epoch ) ? int $epoch : time; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 0 | my ( $result, $sth ) = $this->_execute( $table, 'select', $epoch, $epoch ); | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $result = $sth->fetchall_arrayref() if $result; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return wantarray ? @$result : $result; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | sub expire ## delete expired records from a table | ||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
expire: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 81 | 0 | my ( $this, $table, $epoch ) = @_; | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $epoch = _numeric( $epoch ) ? int $epoch : time; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 0 | my $result = $this->_execute( $table, 'expire', int $epoch ); | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | sub _statement | ||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_statement: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | my ( $this, $table ) = @_; | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | DynGig::Util::EZDB::_statement( $this, $table ); | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | my $dbh = $this->{dbh}; | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $sth = $this->{sth}{$table} ||= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$this->{"sth"}{$table} ||= {}
MC/DC0%0/1
$this->{"sth"}{$table} ||= {}
$this->{"sth"}{$table}
Truth table0%0/2
A
A= $this->{"sth"}{$table}
| |||||||||||||||||||||||||||||||||||
| 96 | 0 | my $neat = DBI::neat( $table ); | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 0 | my %op = | |||||||||||||||||||||||||||||||||
| 99 | ( | ||||||||||||||||||||||||||||||||||
| 100 | expire => 'DELETE FROM %s WHERE omega < ?', | ||||||||||||||||||||||||||||||||||
| 101 | select => 'SELECT * FROM %s WHERE alpha <= ? AND omega >= ?', | ||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | map { $sth->{$_} = $dbh->prepare( sprintf $op{$_}, $neat ) } keys %op; | |||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | sub _numeric | ||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_numeric: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return defined $_[0] && ! ref $_[0] && $_[0] =~ /^\d+(\.\d+)?$/; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $_[0] && !ref($_[0]) && $_[0] =~ /^\d+(\.\d+)?$/
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] && !ref($_[0]) && $_[0] =~ /^\d+(\.\d+)?$/
defined $_[0]
not ref $_[0]
$_[0] =~ /^\d+(\.\d+)?$/
Truth table0%0/4
A and not(B) && C
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^\d+(\.\d+)?$/
| |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | =head1 NOTE | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | See DynGig::Automata | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||