R53/AtomicChange.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod n/a totaltotal 97.7% 87 / 89 CC 2 SCAR 1.5
CC
2
Cov
99%
__ANON__
2.0
_build_changes
2.0
BEGIN
1.0
CRAP 1.2
« R53/ChangeInfo.pm ↑ Summary R53/Role/ParentR53.pm »
1 #
2 # This file is part of Net-Amazon-R53
3 #
4 # This software is Copyright (c) 2012 by Campus Explorer, Inc.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Net::Amazon::R53::AtomicChange;
11 {
12 1 $Net::Amazon::R53::AtomicChange::VERSION = '0.002'; # TRIAL
13 }
14  
15 # ABSTRACT: Representation of an atomic change
16  
17 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use aliased 'MooseX::CoercePerAttribute';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use constant ArrayOfStubs => 'ArrayRef[Net::Amazon::R53::ResourceRecordSet::Stub]';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use constant ArrayOfChanges => 'ArrayRef[Net::Amazon::R53::ResourceRecordSet::Change]';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use constant HZ => class_type 'Net::Amazon::R53::HostedZone';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use constant Stub => class_type 'Net::Amazon::R53::ResourceRecordSet::Stub';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use constant Change => class_type 'Net::Amazon::R53::ResourceRecordSet::Change';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 with 'MooseX::Traitor';
34 1 with 'Net::Amazon::R53::Role::ParentR53';
35  
36  
37 has [ qw{ alpha omega } ] => (
38 traits => [ CoercePerAttribute ],
39 is => 'ro',
40 isa => ArrayOfStubs,
41 required => 1,
42 coerce => {
43 0 ▶ HZ, sub { $_->resource_record_sets },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 },
45 1 );
46  
47  
48 1 has [ qw{ to_delete to_create } ] => (
49 is => 'lazy',
50 isa => ArrayOfStubs,
51 builder => 1,
52 init_arg => undef,
53 );
54  
55 5 ▶sub _build_to_delete { shift->__builder('DELETE') }
Subroutine _build_to_delete: called CC=1 SCAR=0.0
56 5 ▶sub _build_to_create { shift->__builder('CREATE') }
Subroutine _build_to_create: called CC=1 SCAR=0.0
57  
58 10 ▶sub __builder {
Subroutine __builder: called CC=1 SCAR=0.0
59 10 my ($self, $action) = @_;
60  
61 my @records =
62 4 map { $_->record }
63 10 grep { $_->action eq $action }
64 $self->changes->flatten
65 ;
66  
67 10 return \@records;
68 }
69  
70  
71 1 has changes => (
72 traits => ['Array'],
73 is => 'lazy',
74 isa => ArrayOfChanges,
75 init_arg => undef,
76  
77 handles => {
78 null_changeset => 'is_empty',
79 has_no_changes => 'is_empty',
80 has_changes => 'count',
81 number_of_changes => 'count',
82 all_changes => 'elements',
83 },
84 );
85  
86 5 ▶sub _build_changes {
Subroutine _build_changes: called CC=2 SCAR=6.9
87 5 my $self = shift @_;
88  
89 5 my $alpha = $self->alpha;
90 5 my $omega = $self->omega;
91  
92 # in alpha but not omega -> delete
93 # in omega but not alpha -> add
94 5 my @delete = grep { $omega->none == $_ } $alpha->flatten;
95 5 my @create = grep { $alpha->none == $_ } $omega->flatten;
96  
97 # return early if there's nothing left to do
98 5 ▶ return [] unless @delete + @create;
Branch: 1 branch
BranchTrueFalseTotal
unless @delete + @create 2 3 5
99  
100 # only @create and @delete matter for our purposes anymore;
101 # the rest are irrelevant to our operation
102  
103 3 my $_create = do {
104 3 my $class = $self->resource_record_set__change_class;
105 3 my $r53 = $self->r53;
106 3 ▶ sub { $class->new(r53 => $r53, action => shift, record => shift) };
Subroutine __ANON__: called CC=1 SCAR=0.0
107 };
108  
109 return [
110 2 ( map { $_create->(CREATE => $_) } @create ),
111 3 ( map { $_create->(DELETE => $_) } @delete ),
112 ];
113 }
114  
115 1 __PACKAGE__->meta->make_immutable;
116 1 !!42;
117  
118 __END__
« R53/ChangeInfo.pm ↑ Summary R53/Role/ParentR53.pm »