File Coverage

blib/lib/Test/DBChanges/Role/Triggers.pm
Criterion Covered Total %
statement 8 18 44.4
branch n/a
condition 0 2 0.0
subroutine 3 6 50.0
pod 1 2 50.0
total 12 28 42.8


line stmt bran cond sub pod time code
1             package Test::DBChanges::Role::Triggers;
2 2     2   1246 use Moo::Role;
  2         4  
  2         15  
3 2     2   757 use 5.024;
  2         8  
4 2     2   29 use namespace::autoclean;
  2         6  
  2         12  
5              
6             our $VERSION = '1.0.1'; # VERSION
7             # ABSTRACT: fetches data recorded by triggers
8              
9              
10 0     0 1   sub db_item_prefix { 'test_dbchanges' }
11 0     0     sub _table_name { shift->db_item_prefix . '_table' }
12              
13             requires qw(_db_fetch maybe_prepare_db decode_recorded_data _make_changeset);
14              
15             sub changeset_for_code {
16 0     0 0   my ($self,$coderef) = @_;
17              
18 0           $self->maybe_prepare_db;
19 0           my $table_name = $self->_table_name;
20              
21             my $last_id = $self->_db_fetch("SELECT MAX(id) AS id FROM ${table_name}")
22 0   0       ->[0]{id} // 0;
23              
24 0           $coderef->();
25              
26 0           my $rows = $self->_db_fetch(<<"SQL",$last_id);
27             SELECT *
28             FROM ${table_name}
29             WHERE id > ?
30             ORDER BY id ASC
31             SQL
32              
33             $_->{data} = $self->decode_recorded_data($_->{data})
34 0           for $rows->@*;
35              
36 0           return $self->_make_changeset($rows);
37             }
38              
39             1;
40              
41             __END__