StateMigrations/SchemaState.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 86 CC 4 SCAR 17.0
CC
4
Cov
0%
filtered_DiffState
12.0
validate_fingerprint
6.0
_normalize_fingerprint
2.0
CRAP 5.5
1 package DBIx::Class::StateMigrations::SchemaState;
2  
3 use strict;
4 use warnings;
5  
6 # ABSTRACT: Individual schema state
7  
8 use Moo;
9 use Types::Standard qw(:all);
10  
11  
12 has 'fingerprint', is => 'ro', lazy => 1, default => sub {
13 my $self = shift;
14 die __PACKAGE__ . ' must supply either a checksum "fingerprint" or "DiffState"' unless ($self->DiffState);
15 $self->_normalize_fingerprint( $self->filtered_DiffState->fingerprint )
16 }, isa => Str;
17  
18 sub _normalize_fingerprint {
19 my $self = shift;
20 my $fp = shift or return undef;
21 $fp =~ s/\-/_/g;
22 return $fp
23 }
24  
25  
26 has 'DiffState' => (
27 is => 'rwp', lazy => 1,
28 isa => Maybe[InstanceOf['DBIx::Class::Schema::Diff::State']],
29 default => sub { undef }
30 );
31  
32 sub _clear_DiffState {
33 my $self = shift;
34 $self->fingerprint; # make sure we've already recorded the fingerprint
35 $self->_set_DiffState( undef )
36 }
37  
38  
39 has 'diff_filters', is => 'ro', default => sub {[]}, isa => ArrayRef;
40  
41 sub filtered_DiffState {
42 my $self = shift;
43
44 my $State = $self->DiffState or return undef;
45 my @chain = @{ $self->diff_filters };
46 while (scalar(@chain) > 0) {
47 my $meth = shift @chain;
48 die "bad diff_filters - argument list must be even" unless (scalar(@chain) > 0);
49
50 die "bad diff_filters method '$meth' - only 'filter' or 'filter_out' supported" unless (
51 $meth eq 'filter' || $meth eq 'filter_out'
52 );
53
54 my $arg = shift @chain;
55 $State = $State->$meth($arg)
56 }
57
58 $State
59 }
60  
61 sub validate_fingerprint {
62 my $self = shift;
63 my $fp = $self->fingerprint or die "Couldn't obtain fingerprint";
64
65 if($self->DiffState) {
66 my $fresh_fp = $self->_normalize_fingerprint(
67 $self->filtered_DiffState->fingerprint
68 ) or die "Failed to obtain fingerprint from DiffState data";
69
70 $fp eq $fresh_fp or die (
71 "The recalculated fingerprint of the filtered DiffState data ($fresh_fp) does not match the declared/supplied fingerprint ($fp)"
72 )
73 }
74 }
75  
76  
77 1;
78  
79 __END__