Load/Method.pm

filter: Statementstmt 95.5% 65 / 68 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 9 / 9 totaltotal 92.7% 102 / 110 SCAR 26.5
CC
14
Cov
91%
replace
4.0
default
3.5
name
3.5
CRAP 14.1
« Load.pm ↑ Summary Load/Util.pm »
1 package SQL::Load::Method;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 use SQL::Load::Util qw/
6 parse
7 name_list
8 5 ▶/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 27 ▶ my ($class, $content) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12
13 27 my ($data, $hash, $keys, $list) = $class->_parse($content);
14
15 27 my $self = {
16 _data => $data,
17 _hash => $hash,
18 _keys => $keys,
19 _list => $list,
20 _next => 0
21 };
22
23 27 return bless $self, $class;
24 }
25  
26 sub default {
27 4 ▶ my $self = shift;
Subroutine default: called CC=3 SCAR=12.5
Pod documented
28
29 4 ▶ return $self->{_hash}->{default} if exists $self->{_hash}->{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_hash"}{"default"} 0 4 4
30 4 ▶ return $self->{_list}->[0] if exists $self->{_list}->[0];
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_list"}[0] 4 0 4
31
32 0 return;
33 }
34  
35 sub name {
36 41 ▶ my ($self, $name) = @_;
Subroutine name: called CC=3 SCAR=12.5
Pod documented
37
38 41 ▶ my $real = exists $self->{_keys}->{$name} ? $self->{_keys}->{$name} : $name;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_keys'}{$name} ? : 41 0 41
39
40 41 ▶ return $self->{_hash}->{$real} if exists $self->{_hash}->{$real};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_hash"}{$real} 41 0 41
41
42 0 return;
43 }
44  
45 sub next {
46 14 ▶ my $self = shift;
Subroutine next: called CC=3 SCAR=11.0
Pod documented
47
48 14 ▶ if (defined $self->{_next}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_next"}) 13 1 14
49 13 my $next = $self->{_next}++;
50
51 13 ▶ return $self->{_list}->[$next] if exists $self->{_list}->[$next];
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_list"}[$next] 10 3 13
52
53 3 $self->{_next} = undef;
54 }
55
56 4 return;
57 }
58  
59 sub at {
60 8 ▶ my ($self, $index) = @_;
Subroutine at: called CC=2 SCAR=8.1
Pod documented
61
62 8 ▶ return $self->{_list}->[$index - 1] if exists $self->{_list}->[$index - 1];
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_list"}[$index - 1] 8 0 8
63
64 0 return;
65 }
66  
67 sub first {
68 5 ▶ my $self = shift;
Subroutine first: called CC=1 SCAR=0.0
Pod documented
69
70 5 return $self->{_list}->[0];
71 }
72  
73 sub last {
74 1 ▶ my $self = shift;
Subroutine last: called CC=1 SCAR=0.0
Pod documented
75
76 1 return $self->{_list}->[-1];
77 }
78  
79 sub replace {
80 3 ▶ my $self = shift;
Subroutine replace: called CC=4 SCAR=13.9
Pod documented
81
82 3 my %replace = @_;
83
84 3 for my $name (keys %replace) {
85 3 my $value = $replace{$name};
86
87 # replace in hash
88 3 for my $key (keys %{$self->{_hash}}) {
89 5 $self->{_hash}->{$key} =~ s/${name}/${value}/g;
90 }
91
92 # replace in list
93 3 ▶ for (my $i = 0; $i < scalar(@{$self->{_list}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"_list"};}) 5 3 8
94 5 $self->{_list}->[$i] =~ s/${name}/${value}/g;
95 }
96 }
97
98 3 return $self;
99 }
100  
101 sub reset {
102 2 ▶ my $self = shift;
Subroutine reset: called CC=2 SCAR=6.9
Pod documented
103
104 2 my @data = @{$self->{_data}};
105
106 # reset hash
107 2 my %hash = @data;
108 2 $self->{_hash} = \%hash;
109
110 # reset list
111 2 my @list;
112 2 ▶ for (my $i = 0; $i < scalar(@data); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @data) 4 2 6
113 4 push(@list, $data[$i + 1]);
114 }
115 2 $self->{_list} = \@list;
116
117 # reset next
118 2 $self->{_next} = 0;
119
120 2 return $self;
121 }
122  
123 sub _parse {
124 27 ▶ my ($self, $content) = @_;
Subroutine _parse: called CC=3 SCAR=11.0
125
126 27 my @data = parse($content);
127 27 my %hash = @data;
128 27 my %keys;
129 my @list;
130
131 27 ▶ for (my $i = 0; $i < scalar(@data); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @data) 140 27 167
132 140 my $name = $data[$i];
133 140 my @name_list = name_list($name);
134
135 140 for (@name_list) {
136 420 $keys{$_} = $name;
137 }
138
139 140 push(@list, $data[$i + 1]);
140 }
141
142 27 return (\@data, \%hash, \%keys, \@list);
143 }
144  
145 5 1;
146  
147 __END__
« Load.pm ↑ Summary Load/Util.pm »