Diff.pm

filter: Statementstmt 100% 73 / 73 Branchbran 100% 14 / 14 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 100% 17 / 17 Podpod 100% 2 / 2 totaltotal 98.3% 118 / 120 CC 12 SCAR 11.5
CC
12
Cov
99%
_coerce_filter_args
7.0
filter
4.0
__ANON__
3.0
CRAP 3.1
« Diff/SchemaData.pm ↑ Summary Diff/InfoPacket.pm »
1 package DBIx::Class::Schema::Diff;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Simple Diffing of DBIC Schemas
6  
7 4 our $VERSION = '1.02';
8  
9 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 with 'DBIx::Class::Schema::Diff::Role::Common';
11  
12 4 ▶use Types::Standard qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Hash::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Array::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use DBIx::Class::Schema::Diff::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use DBIx::Class::Schema::Diff::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 has '_schema_diff', required => 1, is => 'ro', isa => InstanceOf[
23 'DBIx::Class::Schema::Diff::Schema'
24 ], coerce => \&_coerce_schema_diff;
25  
26 has 'diff', is => 'ro', lazy => 1, default => sub {
27 22 ▶ (shift)->_schema_diff->diff
Subroutine __ANON__: called CC=1 SCAR=0.0
28 4 }, isa => Maybe[HashRef];
29  
30 has 'MatchLayout', is => 'ro', lazy => 1, default => sub {
31 30 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
32
33 30 Hash::Layout->new({
34 default_key => '*',
35 default_value => 1,
36 levels => [
37 {
38 name => 'source',
39 delimiter => ':',
40 registered_keys => [$self->_schema_diff->all_source_names]
41 },{
42 name => 'type',
43 delimiter => '/',
44 registered_keys => [&_types_list]
45 },{
46 name => 'id',
47 }
48 ]
49 });
50  
51 4 }, init_arg => undef, isa => InstanceOf['Hash::Layout'];
52  
53  
54 around BUILDARGS => sub {
55 89 ▶ my ($orig, $self, @args) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
56 89 ▶ my %opt = (ref($args[0]) eq 'HASH') ? %{ $args[0] } : @args; # <-- arg as hash or hashref
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 65 24 89
57
58 89 ▶ return $opt{_schema_diff} ? $self->$orig(%opt) : $self->$orig( _schema_diff => \%opt );
Branch: 1 branch
BranchTrueFalseTotal
$opt{'_schema_diff'} ? : 65 24 89
59 4 };
60  
61  
62 sub filter {
63 65 ▶ my ($self,@args) = @_;
Subroutine filter: called CC=4 SCAR=13.9
Pod documented
64 65 my $params = $self->_coerce_filter_args(@args);
65
66 65 my $Filter = DBIx::Class::Schema::Diff::Filter->new( $params ) ;
67 65 my $diff = $Filter->filter( $self->diff );
68
69 # Make a second pass, using the actual matched paths to filter out
70 # the intermediate paths that didn't actually match anything:
71 # (update: unless this is an empty match, in which case we will just
72 # return the whole diff as-is)
73 65 ▶ if($Filter->mode eq 'limit' && ! $Filter->empty_match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Filter->mode eq "limit" and not $Filter->empty_match) 41 24 65
Condition100%3/3
$Filter->mode eq "limit" and not $Filter->empty_match
!ll&&!rl&&r
19541
MC/DC100%2/2
$Filter->mode eq "limit" and not $Filter->empty_match
$Filter->mode eq "limit" not $Filter->empty_match
Truth table100%3/3
A and not(B)
A= $Filter->mode eq "limit"B= not $Filter->empty_match
ABresult
0X0
100
111
74 41 ▶ if(scalar(@{$Filter->matched_paths}) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$Filter->matched_paths;} > 0) { } 40 1 41
75 $params->{match} = $Filter->match->clone->reset->load( map {
76 196 $Filter->match->path_to_composite_key(@$_)
77 40 } @{$Filter->matched_paths} );
78 40 $Filter = DBIx::Class::Schema::Diff::Filter->new( $params ) ;
79 40 $diff = $Filter->filter( $diff );
80 }
81 else {
82 # If nothing was matched, in limit mode, the diff is undef:
83 1 $diff = undef;
84 }
85 }
86
87 65 return __PACKAGE__->new({
88 _schema_diff => $self->_schema_diff,
89 diff => $diff
90 });
91 }
92  
93 sub filter_out {
94 19 ▶ my ($self,@args) = @_;
Subroutine filter_out: called CC=1 SCAR=0.0
Pod documented
95 19 my $params = $self->_coerce_filter_args(@args);
96 19 $params->{mode} = 'ignore';
97 19 return $self->filter( $params );
98 }
99  
100  
101 sub _coerce_filter_args {
102 84 ▶ my ($self,@args) = @_;
Subroutine _coerce_filter_args: called CC=7 SCAR=19.5
103
104 84 ▶ my $params = (
Branch: 1 branch
BranchTrueFalseTotal
scalar @args > 1 || !ref($args[0]) || ref $args[0] ne 'HASH' ? : 55 29 84
Condition83%5/6
scalar @args > 1 or not ref $args[0] or ref $args[0] ne "HASH"
l!l&&r!l&&!r
55029
scalar @args > 1 or not ref $args[0]
l!l&&r!l&&!r
213429
MC/DC66%2/3
scalar @args > 1 or not ref $args[0] or ref $args[0] ne "HASH"
scalar @args > 1 not ref $args[0] ref $args[0] ne "HASH"
Truth table75%3/4
A or not(B) or C
A= scalar @args > 1B= not ref $args[0]C= ref $args[0] ne "HASH"
ABCresult
1XX1
01X1
0011
0000
105 scalar(@args) > 1
106 || ! ref($args[0])
107 || ref($args[0]) ne 'HASH'
108 ) ? { match => \@args } : $args[0];
109
110 84 ▶ unless (exists $params->{match}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params->{"match"}) 10 74 84
111 10 my $n = { match => $params };
112 10 my @othr = qw(events source_events);
113 10 ▶ exists $n->{match}{$_} and $n->{$_} = delete $n->{match}{$_} for (@othr);
Branch: 1 branch
BranchTrueFalseTotal
exists $n->{"match"}{$_} and $n->{$_} = delete $n->{"match"}{$_} 7 13 20
114 10 $params = $n;
115 }
116  
117 return {
118 %$params,
119 match => $self->MatchLayout->coerce($params->{match})
120 84 };
121 }
122  
123  
124 4 1;
125  
126  
127 __END__
« Diff/SchemaData.pm ↑ Summary Diff/InfoPacket.pm »