File Coverage

blib/lib/DBIx/Class/Schema/Diff/InfoPacket.pm
Criterion Covered Total %
statement 12 13 92.3
branch n/a
condition n/a
subroutine 4 5 80.0
pod n/a
total 16 18 88.8


line stmt bran cond sub pod time code
1             package DBIx::Class::Schema::Diff::InfoPacket;
2 5     5   38 use strict;
  5         13  
  5         156  
3 5     5   27 use warnings;
  5         13  
  5         123  
4              
5 5     5   26 use Moo;
  5         12  
  5         42  
6             with 'DBIx::Class::Schema::Diff::Role::Common';
7              
8 5     5   2029 use Types::Standard qw(:all);
  5         10  
  5         46  
9              
10             has 'name', required => 1, is => 'ro', isa => Str;
11             has 'old_info', required => 1, is => 'ro', isa => Maybe[HashRef];
12             has 'new_info', required => 1, is => 'ro', isa => Maybe[HashRef];
13              
14             has '_source_diff', required => 1, is => 'ro', isa => InstanceOf[
15             'DBIx::Class::Schema::Diff::Source'
16             ];
17              
18             has 'added', is => 'ro', lazy => 1, default => sub {
19             my $self = shift;
20             defined $self->new_info && ! defined $self->old_info
21             }, init_arg => undef, isa => Bool;
22              
23             has 'deleted', is => 'ro', lazy => 1, default => sub {
24             my $self = shift;
25             defined $self->old_info && ! defined $self->new_info
26             }, init_arg => undef, isa => Bool;
27              
28              
29             has 'diff', is => 'ro', lazy => 1, default => sub {
30             my $self = shift;
31            
32             # There is no reason to diff in the case of added/deleted:
33             return { _event => 'added' } if ($self->added);
34             return { _event => 'deleted' } if ($self->deleted);
35            
36             my ($o,$n) = ($self->old_info,$self->new_info);
37             my $diff = $self->_info_diff($o,$n) or return undef;
38            
39             return { _event => 'changed', diff => $diff };
40            
41             }, init_arg => undef, isa => Maybe[HashRef];
42              
43              
44 0     0     sub _schema_diff { (shift)->_source_diff->_schema_diff }
45              
46             1;
47              
48             __END__