File Coverage

blib/lib/Test/DBChanges/ChangeSet.pm
Criterion Covered Total %
statement 14 29 48.2
branch n/a
condition 0 2 0.0
subroutine 5 9 55.5
pod 1 1 100.0
total 20 41 48.7


line stmt bran cond sub pod time code
1             package Test::DBChanges::ChangeSet;
2 2     2   14 use Moo;
  2         4  
  2         15  
3 2     2   750 use 5.024;
  2         16  
4 2     2   20 use Types::Standard qw(HashRef ArrayRef);
  2         6  
  2         14  
5 2     2   2132 use Test::DBChanges::TableChangeSet;
  2         8  
  2         72  
6 2     2   15 use namespace::autoclean;
  2         5  
  2         12  
7             our $VERSION = '1.0.2'; # VERSION
8             # ABSTRACT: set of changes to DB tables
9              
10              
11             has table_source_map => ( is => 'ro', required => 1, isa => HashRef );
12             has _raw_changes => ( is => 'ro', required => 1, isa => ArrayRef[HashRef],
13             init_arg => 'raw_changes' );
14              
15             has _raw_changes_for_table => (
16             is => 'lazy',
17             builder => sub {
18 0     0     my ($self) = @_;
19              
20 0           my %changes_for_table;
21 0           for my $change ($self->_raw_changes->@*) {
22             push $changes_for_table{$change->{table_name}}->@*,
23 0           $change;
24             }
25              
26 0           return \%changes_for_table;
27             },
28             );
29              
30             has changed_tables => (
31             is => 'lazy',
32 0     0     builder => sub { return [ sort keys shift->_raw_changes_for_table->%* ] },
33             );
34              
35             has _changes_for_source => (
36             is => 'lazy',
37             builder => sub {
38 0     0     my ($self) = @_;
39 0           my %changes_for_source;
40              
41 0           for my $table_name (keys $self->table_source_map->%*) {
42 0           my $factory = $self->table_source_map->{$table_name}{factory};
43 0           my $source_name = $self->table_source_map->{$table_name}{name};
44             $changes_for_source{$source_name} = Test::DBChanges::TableChangeSet->new({
45             table_name => $table_name,
46             source_name => $source_name,
47             factory_sub => $factory,
48 0   0       raw_changes => $self->_raw_changes_for_table->{$table_name} // [],
49             });
50             }
51              
52 0           return \%changes_for_source;
53             },
54             );
55              
56              
57              
58             sub changes_for_source {
59 0     0 1   my ($self,$source_name) = @_;
60 0           return $self->_changes_for_source->{$source_name};
61             }
62              
63             1;
64              
65             __END__