| 1 | package DBIx::Class::Schema::Diff::Schema; | ||||||||||
| 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 | # 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 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 4 | with 'DBIx::Class::Schema::Diff::Role::Common'; | |||||||||
| 28 | |||||||||||
| 29 | 4 | ▶ | use Types::Standard qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 4 | ▶ | use Module::Runtime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 4 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 4 | ▶ | use DBIx::Class::Schema::Diff::Source; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 4 | ▶ | use DBIx::Class::Schema::Diff::SchemaData; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 4 | has 'old_schema', required => 1, is => 'ro', isa => InstanceOf[ | |||||||||
| 37 | 'DBIx::Class::Schema::Diff::SchemaData' | ||||||||||
| 38 | ], coerce => \&_coerce_schema_data; | ||||||||||
| 39 | |||||||||||
| 40 | 4 | 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 | 52 | ▶ | my $self = shift; | ||||||||
|
Subroutine
all_source_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | |||||||||||
| 48 | 52 | my ($o,$n) = ($self->old_schema,$self->new_schema); | |||||||||
| 49 | |||||||||||
| 50 | # List of all sources in old, new, or both: | ||||||||||
| 51 | 52 | return uniq($o->sources,$n->sources); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | has 'sources', is => 'ro', lazy => 1, default => sub { | ||||||||||
| 55 | 22 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 56 | |||||||||||
| 57 | return { map { | ||||||||||
| 58 | 22 | $_ => DBIx::Class::Schema::Diff::Source->new( | |||||||||
| 59 | name => $_, | ||||||||||
| 60 | 517 | ▶ | old_source => scalar try{$self->old_schema->source($_)}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 517 | ▶ | new_source => scalar try{$self->new_schema->source($_)}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 517 | _schema_diff => $self, | |||||||||
| 63 | ) | ||||||||||
| 64 | } $self->all_source_names }; | ||||||||||
| 65 | |||||||||||
| 66 | 4 | }, init_arg => undef, isa => HashRef; | |||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | has 'diff', is => 'ro', lazy => 1, default => sub { | ||||||||||
| 70 | 22 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 71 | |||||||||||
| 72 | # TODO: handle added/deleted/changed at this level, too... | ||||||||||
| 73 | my $diff = { map { | ||||||||||
| 74 | 517 | ▶ | $_->diff ? ($_->name => $_->diff) : () | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 22 | } values %{$self->sources} }; | |||||||||
| 76 | |||||||||||
| 77 | 22 | ▶ | return undef unless (keys %$diff > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 13 | return $diff; | |||||||||
| 79 | |||||||||||
| 80 | 4 | }, init_arg => undef, isa => Maybe[HashRef]; | |||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub _schema_diff { (shift) } | ||||||||
|
Subroutine
_schema_diff: not called CC=1 SCAR=6.9
| |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | 4 | 1; | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||