File Coverage

blib/lib/DBIx/Class/Schema/Diff/Schema.pm
Criterion Covered Total %
statement 27 28 96.4
branch n/a
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 36 39 92.3


line stmt bran cond sub pod time code
1             package DBIx::Class::Schema::Diff::Schema;
2 5     5   39 use strict;
  5         13  
  5         156  
3 5     5   35 use warnings;
  5         10  
  5         156  
4              
5             # ABSTRACT: Simple Diffing of DBIC Schemas
6             # VERSION
7              
8             #
9             # TODO (#2)
10             #
11             # The structure/design of this class (+ Source and InfoPacket)
12             # made more sense before adding the 'SchemaData' feature (#1)
13             # when these classes were handling both the data extraction from
14             # DBIC and the diffing tasks of the individual section of data.
15             # Now the data extraction work is done in SchemaData leaving only
16             # simple static hashrefs to be dealt with here. These classes should
17             # probably now be consolidated and generalized. I'm not sure
18             # how important this is though since everything is already working.
19             # Later on, if more types of data need to be diffed besides the
20             # 5 current ones (columns,relationships,constraints,table_name,isa),
21             # or it is useful to make that more dynamic, such as to be able to
22             # add more data-points on the fly, then taking the time for
23             # refactoring these will make more sense... (2014-04-14 by vanstyn)
24             #
25              
26 5     5   36 use Moo;
  5         11  
  5         35  
27             with 'DBIx::Class::Schema::Diff::Role::Common';
28              
29 5     5   2063 use Types::Standard qw(:all);
  5         21  
  5         51  
30 5     5   240120 use Module::Runtime;
  5         16  
  5         84  
31 5     5   329 use Try::Tiny;
  5         14  
  5         435  
32              
33 5     5   3212 use DBIx::Class::Schema::Diff::Source;
  5         22  
  5         285  
34 5     5   2886 use DBIx::Class::Schema::Diff::SchemaData;
  5         21  
  5         2228  
35              
36             has 'old_schema', required => 1, is => 'ro', isa => InstanceOf[
37             'DBIx::Class::Schema::Diff::SchemaData'
38             ], coerce => \&_coerce_schema_data;
39              
40             has 'new_schema', required => 1, is => 'ro', isa => InstanceOf[
41             'DBIx::Class::Schema::Diff::SchemaData'
42             ], coerce => \&_coerce_schema_data;
43              
44              
45             sub all_source_names {
46 53     53 0 122 my $self = shift;
47            
48 53         337 my ($o,$n) = ($self->old_schema,$self->new_schema);
49            
50             # List of all sources in old, new, or both:
51 53         358 return uniq($o->sources,$n->sources);
52             }
53              
54             has 'sources', is => 'ro', lazy => 1, default => sub {
55             my $self = shift;
56            
57             return { map {
58             $_ => DBIx::Class::Schema::Diff::Source->new(
59             name => $_,
60             old_source => scalar try{$self->old_schema->source($_)},
61             new_source => scalar try{$self->new_schema->source($_)},
62             _schema_diff => $self,
63             )
64             } $self->all_source_names };
65            
66             }, init_arg => undef, isa => HashRef;
67              
68              
69             has 'diff', is => 'ro', lazy => 1, default => sub {
70             my $self = shift;
71            
72             # TODO: handle added/deleted/changed at this level, too...
73             my $diff = { map {
74             $_->diff ? ($_->name => $_->diff) : ()
75             } values %{$self->sources} };
76            
77             return undef unless (keys %$diff > 0);
78             return $diff;
79            
80             }, init_arg => undef, isa => Maybe[HashRef];
81              
82 0     0     sub _schema_diff { (shift) }
83              
84              
85             1;
86              
87             __END__