blib/lib/WWW/Shopify/Common/DBIxGroup.pm

filter: Statementstmt 9.8% 7 / 71 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 14.2% 2 / 14 Podpod 0.0% 0 / 12 totaltotal 6.1% 9 / 147 CC 26 SCAR 39.5
CC
26
Cov
6%
ensure_synchronicity
132.0
add_children
56.0
update_or_insert
20.0
CRAP 51.7
« blib/lib/WWW/Shopify/Model/Item.pm ↑ Summary blib/lib/WWW/Shopify.pm »
1 #!/usr/bin/perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package WWW::Shopify::Common::DBIxGroup;
7  
8 sub new {
9 0 ▶ my $package = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
10 0 my %hash = @_;
11 bless {
12 parent => undef,
13 0 ▶ contents => $hash{'contents'} ? $hash{'contents'} : undef,
Branch: 1 branch
BranchTrueFalseTotal
$hash{'contents'} ? : 0 0 0
14 children => []
15 }, $package;
16 }
17  
18 0 ▶sub children { return @{$_[0]->{children}}; }
Subroutine children: not called CC=1 SCAR=6.9
Pod undocumented
19 0 ▶sub contents { return $_[0]->{contents}; }
Subroutine contents: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub parent { $_[0]->{parent} = $_[1] if $_[1]; return $_[0]->{parent}; }
Subroutine parent: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 0 0
21 0 ▶sub members { return ($_[0]->contents, $_[0]->children); }
Subroutine members: not called CC=1 SCAR=6.9
Pod undocumented
22 sub add_children {
23 0 ▶ my ($self, @children) = @_;
Subroutine add_children: not called CC=7 SCAR=40.3
Pod undocumented
24  
25 0 ▶ @children = @{$children[0]} if int(@children) == 1 && ref($children[0]) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if int @children == 1 and ref $children[0] eq "ARRAY" 0 0 0
Condition0%0/3
int @children == 1 and ref $children[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
int @children == 1 and ref $children[0] eq "ARRAY"
int @children == 1 ref $children[0] eq "ARRAY"
Truth table0%0/3
A and B
A= int @children == 1B= ref $children[0] eq "ARRAY"
ABresult
0X0
100
111
26 0 foreach my $child (@children) {
27 0 ▶ die new WWW::Shopify::Exception("Must be a DBIxGroup: " . ref($child)) unless $child && ref($child) && ref($child) =~ m/DBIxGroup/;
Branch: 1 branch
BranchTrueFalseTotal
unless $child and ref $child and ref($child) =~ /DBIxGroup/ 0 0 0
Condition0%0/6
$child and ref $child and ref($child) =~ /DBIxGroup/
!ll&&!rl&&r
000
$child and ref $child
!ll&&!rl&&r
000
MC/DC0%0/3
$child and ref $child and ref($child) =~ /DBIxGroup/
$child ref $child ref($child) =~ /DBIxGroup/
Truth table0%0/4
A and B and C
A= $childB= ref $childC= ref($child) =~ /DBIxGroup/
ABCresult
0XX0
10X0
1100
1111
28 0 $child->parent($self);
29 0 push(@{$self->{children}}, $child);
30 }
31 }
32 sub update {
33 0 ▶ my ($self) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
34 0 $_->update_or_insert for ($self->children);
35 0 $self->contents->update;
36 }
37 sub delete {
38 0 ▶ my ($self) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod undocumented
39 0 $_->delete for ($self->children);
40 0 $self->contents->delete;
41 }
42 sub update_or_insert {
43 0 ▶ my ($self) = @_;
Subroutine update_or_insert: not called CC=4 SCAR=30.0
Pod undocumented
44 0 ▶ if ($self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent) { } 0 0 0
45 0 my $relationship = "add_to_" . $self->contents->represents->plural;
46 0 my $columns = {$self->contents->get_columns};
47 0 ▶ if (!$self->contents->in_storage) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->contents->in_storage) { } 0 0 0
48 0 $self->parent->contents->$relationship($columns);
49 }
50 else {
51 0 $self->contents->update;
52 }
53 }
54 else {
55 0 $self->contents->update_or_insert;
56 }
57 0 $_->update_or_insert for ($self->children);
58 }
59 sub insert {
60 0 ▶ my ($self) = @_;
Subroutine insert: not called CC=3 SCAR=24.8
Pod undocumented
61 0 ▶ if ($self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent) { } 0 0 0
62 0 my $relationship = "add_to_" . $self->contents->represents->plural;
63 0 my $parent_variable = $self->contents->parent_variable;
64 0 $self->contents->$parent_variable($self->parent->contents->id);
65 0 my $columns = {$self->contents->get_columns};
66 0 $self->parent->contents->$relationship($columns);
67 }
68 else {
69 0 $self->contents->insert;
70 }
71 0 $_->insert for ($self->children);
72 }
73  
74 # Ensure that we have no unecessary children present.
75 sub ensure_synchronicity {
76 0 ▶ my ($self) = @_;
Subroutine ensure_synchronicity: not called CC=11 SCAR=48.8
Pod undocumented
77 0 my $package = $self->contents->represents;
78 0 my $fields = $package->fields;
79 0 ▶ foreach my $field (grep { $_->is_relation && ($_->is_many || $_->is_own) && $_->relation !~ m/Metafield/ } values(%$fields)) {
Branch: 1 branch
BranchTrueFalseTotal
$_->is_relation and $_->is_many || $_->is_own and not $_->relation =~ /Metafield/ 0 0 0
Condition0%0/6
$_->is_relation and $_->is_many || $_->is_own
!ll&&!rl&&r
000
$_->is_many or $_->is_own
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->is_relation and $_->is_many || $_->is_own
$_->is_relation $_->is_many $_->is_own
Truth table0%0/4
A and B or C
A= $_->is_relationB= $_->is_manyC= $_->is_own
ABCresult
0XX0
1000
11X1
1011
80 0 my $name = $field->name;
81 0 my @children = grep { $_->contents->represents eq $field->relation } $self->children;
82 # In case we're not actually keeping certain elements in sync.
83 0 eval {
84 0 my @ids = $field->relation->identifier;
85 0 ▶ if (int(@ids) == 1 && $ids[0] eq "id") {
Branch: 1 branch
BranchTrueFalseTotal
if (int @ids == 1 and $ids[0] eq 'id') { } 0 0 0
Condition0%0/3
int @ids == 1 and $ids[0] eq "id"
!ll&&!rl&&r
000
MC/DC0%0/2
int @ids == 1 and $ids[0] eq "id"
int @ids == 1 $ids[0] eq "id"
Truth table0%0/3
A and B
A= int @ids == 1B= $ids[0] eq "id"
ABresult
0X0
100
111
86 0 $self->contents->$name->search({ id => { -not_in => [map { $_->contents->id } @children] } })->delete;
87 } else {
88 0 my @db_children = $self->contents->$name->all;
89 0 for my $db_child (@db_children) {
90 0 my $exists = 0;
91 0 for my $pot_child (@children) {
92 0 ▶ $exists = 1 if int(grep { $db_child->$_ eq $pot_child->contents->$_ } (@ids)) == int(@ids);
Branch: 1 branch
BranchTrueFalseTotal
if int grep({$db_child->$_ eq $pot_child->contents->$_;} @ids) == int @ids 0 0 0
93 }
94 0 ▶ $db_child->delete if !$exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 0 0 0
95 }
96 }
97 };
98 }
99 }
100  
101 0 ▶sub nested { my ($self) = @_; return ($self->contents, map { $_->nested } $self->children); }
Subroutine nested: not called CC=1 SCAR=6.9
Pod undocumented
102  
103 1 1;
« blib/lib/WWW/Shopify/Model/Item.pm ↑ Summary blib/lib/WWW/Shopify.pm »