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

filter: Statementstmt 11.8% 7 / 59 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 14.2% 2 / 14 Podpod 0.0% 0 / 12 totaltotal 7.2% 9 / 124 CC 20 SCAR 30.8
CC
20
Cov
8%
add_children
56.0
ensure_synchronicity
30.0
update_or_insert
20.0
CRAP 21.7
« blib/lib/WWW/Shopify/Model/LinkList/Link.pm ↑ Summary blib/lib/WWW/Shopify/Public.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 $columns = {$self->contents->get_columns};
64 0 $self->parent->contents->$relationship($columns);
65 }
66 else {
67 0 $self->contents->insert;
68 }
69 0 $_->insert for ($self->children);
70 }
71  
72 # Ensure that we have no unecessary children present.
73 sub ensure_synchronicity {
74 0 ▶ my ($self) = @_;
Subroutine ensure_synchronicity: not called CC=5 SCAR=34.0
Pod undocumented
75 0 my $package = $self->contents->represents;
76 0 my $fields = $package->fields;
77 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
78 0 my $name = $field->name;
79 0 my @children = grep { $_->contents->represents eq $field->relation } $self->children;
80 0 $self->contents->$name->search({ id => { -not_in => [map { $_->contents->id } @children] } })->delete;
81 }
82 }
83  
84 0 ▶sub nested { my ($self) = @_; return ($self->contents, map { $_->nested } $self->children); }
Subroutine nested: not called CC=1 SCAR=6.9
Pod undocumented
85  
86 1 1;
« blib/lib/WWW/Shopify/Model/LinkList/Link.pm ↑ Summary blib/lib/WWW/Shopify/Public.pm »