Diff/Source.pm

filter: Statementstmt 99.0% 108 / 109 Branchbran 79.5% 35 / 44 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 95.4% 21 / 22 Podpod n/a totaltotal 90.8% 169 / 186 CC 26 SCAR 18.3
CC
26
Cov
92%
__ANON__
15.0
__ANON__
4.0
__ANON__
3.0
CRAP 6.2
« Diff/Filter.pm ↑ Summary Diff/SchemaData.pm »
1 package DBIx::Class::Schema::Diff::Source;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 with 'DBIx::Class::Schema::Diff::Role::Common';
7  
8 5 ▶use Types::Standard qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use List::MoreUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use DBIx::Class::Schema::Diff::InfoPacket;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 has 'name', required => 1, is => 'ro', isa => Str;
15 0 ▶has 'old_source', is => 'ro', isa => Maybe[HashRef], default => sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 5 has 'new_source', required => 1, is => 'ro', isa => Maybe[HashRef];
17  
18 517 ▶has 'diff_added', is => 'ro', isa => Bool, default => sub { 0 };
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 5 has '_schema_diff', required => 1, is => 'ro', isa => InstanceOf[
21 'DBIx::Class::Schema::Diff::Schema'
22 ];
23  
24 has 'added', is => 'ro', lazy => 1, default => sub {
25 506 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=7.2
26 506 ▶ defined $self->new_source && ! defined $self->old_source
Branch: 1 branch
BranchTrueFalseTotal
defined $self->new_source and not defined $self->old_source 506 0 506
27 5 }, init_arg => undef, isa => Bool;
28  
29 has 'deleted', is => 'ro', lazy => 1, default => sub {
30 517 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
31 517 ▶ defined $self->old_source && ! defined $self->new_source
Branch: 1 branch
BranchTrueFalseTotal
defined $self->old_source and not defined $self->new_source 506 11 517
32 5 }, init_arg => undef, isa => Bool;
33  
34  
35 has 'columns', is => 'ro', lazy => 1, default => sub {
36 495 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
37
38 495 my ($o,$n) = ($self->old_source,$self->new_source);
39
40 # List of all columns in old, new, or both:
41 495 ▶ my @columns = uniq(try{keys %{$o->{columns}}}, try{keys %{$n->{columns}}});
Subroutine __ANON__: called CC=1 SCAR=0.0
42
43 return {
44 495 map { $_ => $self->_new_InfoPacket(
45 name => $_,
46 old_info => $o ? $o->{columns}{$_} : undef,
47 2862 ▶ new_info => $n ? $n->{columns}{$_} : undef,
Branch: 2 branches
BranchTrueFalseTotal
$o ? : 2862 0 2862
$n ? : 2862 0 2862
48 ) } @columns
49 };
50  
51 5 }, init_arg => undef, isa => HashRef;
52  
53  
54 has 'relationships', is => 'ro', lazy => 1, default => sub {
55 495 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
56
57 495 my ($o,$n) = ($self->old_source,$self->new_source);
58
59 # List of all relationships in old, new, or both:
60 495 ▶ my @rels = uniq(try{keys %{$o->{relationships}}}, try{keys %{$n->{relationships}}});
Subroutine __ANON__: called CC=1 SCAR=0.0
61
62 return {
63 495 map { $_ => $self->_new_InfoPacket(
64 name => $_,
65 old_info => $o ? $o->{relationships}{$_} : undef,
66 957 ▶ new_info => $n ? $n->{relationships}{$_} : undef,
Branch: 2 branches
BranchTrueFalseTotal
$o ? : 957 0 957
$n ? : 957 0 957
67 ) } @rels
68 };
69
70 5 }, init_arg => undef, isa => HashRef;
71  
72  
73 has 'constraints', is => 'ro', lazy => 1, default => sub {
74 495 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.1
75
76 495 my ($o,$n) = ($self->old_source,$self->new_source);
77
78 # List of all unique_constraint_names in old, new, or both:
79 495 ▶ my @consts = uniq(try{keys %{$o->{constraints}}}, try{keys %{$n->{constraints}}});
Subroutine __ANON__: called CC=1 SCAR=0.0
80
81 return {
82 495 map { $_ => $self->_new_InfoPacket(
83 name => $_,
84 old_info => $o ? $o->{constraints}{$_} : undef,
85 418 ▶ new_info => $n ? $n->{constraints}{$_} : undef,
Branch: 2 branches
BranchTrueFalseTotal
$o ? : 418 0 418
$n ? : 418 0 418
86 ) } @consts
87 };
88
89 5 }, init_arg => undef, isa => HashRef;
90  
91  
92 has 'isa_diff', is => 'ro', lazy => 1, default => sub {
93 495 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
94  
95 495 my ($o,$n) = ($self->old_source,$self->new_source);
96  
97 495 ▶ my $o_isa = $o ? $o->{isa} : [];
Branch: 1 branch
BranchTrueFalseTotal
$o ? : 495 0 495
98 495 ▶ my $n_isa = $n ? $n->{isa} : [];
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 495 0 495
99
100 495 my $AD = Array::Diff->diff($o_isa,$n_isa);
101 my $diff = [
102 1 (map {'-'.$_} @{$AD->deleted}),
103 495 (map {'+'.$_} @{$AD->added})
104 ];
105  
106 495 ▶ return scalar(@$diff) > 0 ? $diff : undef;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$diff > 0 ? : 11 484 495
107  
108 5 }, init_arg => undef, isa => Maybe[ArrayRef];
109  
110  
111  
112 has 'diff', is => 'ro', lazy => 1, default => sub {
113 517 ▶ my $self = shift;
Subroutine __ANON__: called CC=15 SCAR=27.1
114
115 # There is no reason to diff in the case of added/deleted:
116 517 ▶ return { _event => 'deleted' } if ($self->deleted);
Branch: 1 branch
BranchTrueFalseTotal
if $self->deleted 11 506 517
117 506 ▶ return { _event => 'added' } if ($self->added && ! $self->diff_added);
Branch: 1 branch
BranchTrueFalseTotal
if $self->added and not $self->diff_added 11 495 506
Condition66%2/3
$self->added and not $self->diff_added
!ll&&!rl&&r
495011
MC/DC50%1/2
$self->added and not $self->diff_added
$self->added not $self->diff_added
Truth table66%2/3
A and not(B)
A= $self->addedB= not $self->diff_added
ABresult
0X0
100
111
118
119 495 my $diff = {};
120
121 $diff->{columns} = { map {
122 2862 ▶ $_->diff ? ($_->name => $_->diff) : ()
Branch: 1 branch
BranchTrueFalseTotal
$_->diff ? : 59 2803 2862
123 495 } values %{$self->columns} };
124 495 ▶ delete $diff->{columns} unless (keys %{$diff->{columns}} > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$diff{"columns"};} > 0 470 25 495
125
126 $diff->{relationships} = { map {
127 957 ▶ $_->diff ? ($_->name => $_->diff) : ()
Branch: 1 branch
BranchTrueFalseTotal
$_->diff ? : 33 924 957
128 495 } values %{$self->relationships} };
129 495 ▶ delete $diff->{relationships} unless (keys %{$diff->{relationships}} > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$diff{"relationships"};} > 0 473 22 495
130
131 $diff->{constraints} = { map {
132 418 ▶ $_->diff ? ($_->name => $_->diff) : ()
Branch: 1 branch
BranchTrueFalseTotal
$_->diff ? : 55 363 418
133 495 } values %{$self->constraints} };
134 495 ▶ delete $diff->{constraints} unless (keys %{$diff->{constraints}} > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$diff{"constraints"};} > 0 451 44 495
135
136 495 ▶ my $o_tbl = try{$self->old_source->{table_name}} || '';
Subroutine __ANON__: called CC=1 SCAR=0.2
Condition50%1/2
&try(sub { || ''
l!l
4950
MC/DC0%0/1
&try(sub { $self->old_source->{'table_name'}; } ) || ''
&try(sub { $self->old_source->{'table_name'}; } )
Truth table50%1/2
A
A= &try(sub { $self->old_source->{'table_name'}; } )
Aresult
11
00
137 495 ▶ my $n_tbl = try{$self->new_source->{table_name}} || '';
Subroutine __ANON__: called CC=1 SCAR=0.2
Condition50%1/2
&try(sub { || ''
l!l
4950
MC/DC0%0/1
&try(sub { $self->new_source->{'table_name'}; } ) || ''
&try(sub { $self->new_source->{'table_name'}; } )
Truth table50%1/2
A
A= &try(sub { $self->new_source->{'table_name'}; } )
Aresult
11
00
138 495 ▶ $diff->{table_name} = $n_tbl unless ($o_tbl eq $n_tbl);
Branch: 1 branch
BranchTrueFalseTotal
unless $o_tbl eq $n_tbl 22 473 495
139
140 495 ▶ $diff->{isa} = $self->isa_diff if ($self->isa_diff);
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa_diff 11 484 495
141
142 # TODO: other data points TDB
143 # ...
144
145 # No changes:
146 495 ▶ return undef unless (keys %$diff > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$diff > 0 426 69 495
147
148 69 $diff->{_event} = 'changed';
149 69 return $diff;
150
151 5 }, init_arg => undef, isa => Maybe[HashRef];
152  
153  
154 sub _new_InfoPacket {
155 4237 ▶ my $self = shift;
Subroutine _new_InfoPacket: called CC=1 SCAR=0.0
156 4237 DBIx::Class::Schema::Diff::InfoPacket->new(
157 _source_diff => $self, diff_added => $self->diff_added, @_
158 )
159 }
160  
161  
162 5 1;
163  
164  
165 __END__
166  
167 =pod
168  
169 =head1 NAME
170  
171 DBIx::Class::Schema::Diff::Source - internal object class for DBIx::Class::Schema::Diff
172  
173 =head1 DESCRIPTION
174  
175 This class is used internally by L<DBIx::Class::Schema::Diff> and is not meant to be called directly.
176  
177 Please refer to the main L<DBIx::Class::Schema::Diff> documentation for more info.
178  
179 =head1 AUTHOR
180  
181 Henry Van Styn <vanstyn@cpan.org>
182  
183 =head1 COPYRIGHT AND LICENSE
184  
185 This software is copyright (c) 2014 by IntelliTree Solutions llc.
186  
187 This is free software; you can redistribute it and/or modify it under
188 the same terms as the Perl 5 programming language system itself.
189  
190 =cut
« Diff/Filter.pm ↑ Summary Diff/SchemaData.pm »