| 1 | package DBIx::Class::Schema::Diff::Schema; | ||||||||||
| 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 | # 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 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 5 | with 'DBIx::Class::Schema::Diff::Role::Common'; | |||||||||
| 28 | |||||||||||
| 29 | 5 | ▶ | use Types::Standard qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 5 | ▶ | use Module::Runtime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 5 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 5 | ▶ | use DBIx::Class::Schema::Diff::Source; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 5 | ▶ | use DBIx::Class::Schema::Diff::SchemaData; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 24 | ▶ | has 'new_schema_only', is => 'ro', isa => Bool, default => sub { 0 }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 5 | has 'old_schema', required => 1, is => 'ro', isa => InstanceOf[ | |||||||||
| 39 | 'DBIx::Class::Schema::Diff::SchemaData' | ||||||||||
| 40 | ], coerce => \&_coerce_schema_data; | ||||||||||
| 41 | |||||||||||
| 42 | 5 | has 'new_schema', required => 1, is => 'ro', isa => InstanceOf[ | |||||||||
| 43 | 'DBIx::Class::Schema::Diff::SchemaData' | ||||||||||
| 44 | ], coerce => \&_coerce_schema_data; | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | sub all_source_names { | ||||||||||
| 48 | 53 | ▶ | my $self = shift; | ||||||||
|
Subroutine
all_source_names: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | 53 | ▶ | return $self->new_schema->sources if ($self->new_schema_only); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 53 | my ($o,$n) = ($self->old_schema,$self->new_schema); | |||||||||
| 53 | |||||||||||
| 54 | # List of all sources in old, new, or both: | ||||||||||
| 55 | 53 | return uniq($o->sources,$n->sources); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | has 'sources', is => 'ro', lazy => 1, default => sub { | ||||||||||
| 59 | 22 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 22 | return { map { $_ => $self->_new_Diff_Source($_) } $self->all_source_names }; | |||||||||
| 61 | 5 | }, init_arg => undef, isa => HashRef; | |||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | has 'diff', is => 'ro', lazy => 1, default => sub { | ||||||||||
| 65 | 22 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 66 | |||||||||||
| 67 | # TODO: handle added/deleted/changed at this level, too... | ||||||||||
| 68 | my $diff = { map { | ||||||||||
| 69 | 517 | ▶ | $_->diff ? ($_->name => $_->diff) : () | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 22 | } values %{$self->sources} }; | |||||||||
| 71 | |||||||||||
| 72 | 22 | ▶ | return undef unless (keys %$diff > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 13 | return $diff; | |||||||||
| 74 | |||||||||||
| 75 | 5 | }, init_arg => undef, isa => Maybe[HashRef]; | |||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub _schema_diff { (shift) } | ||||||||
|
Subroutine
_schema_diff: not called CC=1 SCAR=6.9
| |||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | sub _new_Diff_Source { | ||||||||||
| 81 | 517 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_new_Diff_Source: called CC=2 SCAR=7.0
| |||||||||||
| 82 | 517 | my $name = shift; | |||||||||
| 83 | |||||||||||
| 84 | DBIx::Class::Schema::Diff::Source->new( $self->new_schema_only | ||||||||||
| 85 | 517 | ▶ | ? ( diff_added => 1 ) : ( old_source => scalar try{$self->old_schema->source($name)} ), | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 517 | ▶ | new_source => scalar try{$self->new_schema->source($name)}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 87 | 517 | ▶ | name => $name, _schema_diff => $self | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | ) | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | 5 | 1; | |||||||||
| 93 | |||||||||||
| 94 | __END__ | ||||||||||
| 95 | |||||||||||
| 96 | =pod | ||||||||||
| 97 | |||||||||||
| 98 | =head1 NAME | ||||||||||
| 99 | |||||||||||
| 100 | DBIx::Class::Schema::Diff::Schema - internal object class for DBIx::Class::Schema::Diff | ||||||||||
| 101 | |||||||||||
| 102 | =head1 DESCRIPTION | ||||||||||
| 103 | |||||||||||
| 104 | This class is used internally by L<DBIx::Class::Schema::Diff> and is not meant to be called directly. | ||||||||||
| 105 | |||||||||||
| 106 | Please refer to the main L<DBIx::Class::Schema::Diff> documentation for more info. | ||||||||||
| 107 | |||||||||||
| 108 | =head1 AUTHOR | ||||||||||
| 109 | |||||||||||
| 110 | Henry Van Styn <vanstyn@cpan.org> | ||||||||||
| 111 | |||||||||||
| 112 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 113 | |||||||||||
| 114 | This software is copyright (c) 2014 by IntelliTree Solutions llc. | ||||||||||
| 115 | |||||||||||
| 116 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 117 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 118 | |||||||||||
| 119 | =cut | ||||||||||