GenOO/Data/Structure/DoubleHashArray.pm

filter: Statementstmt 97.5% 79 / 81 Branchbran 87.5% 14 / 16 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 10 totaltotal 84.0% 116 / 138 CC 21 SCAR 12.7
CC
21
Cov
92%
foreach_entry_on_secondary_key_do
6.3
foreach_entry_do
6.0
sort_entries
4.0
CRAP 3.6
« GenOO/Data/File/FASTA.pm ↑ Summary GenOO/Spliceable.pm »
1 # POD documentation - main docs before the code
2  
3 =head1 NAME
4  
5 GenOO::Data::Structure::DoubleHashArray - Object for a data structure which corresponds of a 2D hash whose values are references to array
6  
7 =head1 SYNOPSIS
8  
9 # To initialize
10 my $structure = GenOO::Data::Structure::DoubleHashArray->new();
11  
12  
13 =head1 DESCRIPTION
14  
15 This class corresponds to a data structure which is a 2D hash whose primary key could be for
16 example the strand, its secondary key the chromosome and each value an array reference with
17 objects that consume the L<GenOO::Region> role.
18  
19 =head1 EXAMPLES
20  
21 # Add an entry to the structure
22 $structure->add_entry($primary_key, $secondary_key, $entry);
23  
24 =cut
25  
26 # Let the code begin...
27  
28 package GenOO::Data::Structure::DoubleHashArray;
29 1 $GenOO::Data::Structure::DoubleHashArray::VERSION = '1.5.0';
30  
31 #######################################################################
32 ####################### Load External modules #####################
33 #######################################################################
34 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39  
40 #######################################################################
41 ####################### Interface attributes ######################
42 #######################################################################
43 has 'sorting_code_block' => (
44 isa => 'CodeRef',
45 is => 'ro',
46 2 ▶ default => sub { sub {return $_[0] <=> $_[1]} }
Subroutine __ANON__: called CC=1 SCAR=1.2
47 1 );
48  
49 1 has 'entries_count' => (
50 traits => ['Counter'],
51 is => 'ro',
52 isa => 'Num',
53 default => 0,
54 handles => {
55 _inc_entries_count => 'inc',
56 _reset_entries_count => 'reset',
57 },
58 );
59  
60 1 has 'is_sorted' => (
61 traits => ['Bool'],
62 is => 'rw',
63 isa => 'Bool',
64 default => 0,
65 handles => {
66 _set_is_sorted => 'set',
67 _unset_is_sorted => 'unset',
68 is_not_sorted => 'not',
69 },
70 );
71  
72  
73 #######################################################################
74 ######################## Private attributes #######################
75 #######################################################################
76 has '_structure' => (
77 traits => ['Hash'],
78 is => 'ro',
79 isa => 'HashRef[HashRef[ArrayRef]]',
80 59 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 1 );
82  
83  
84 #######################################################################
85 ######################## Interface Methods ########################
86 #######################################################################
87 sub foreach_entry_do {
88 14 ▶ my ($self, $block) = @_;
Subroutine foreach_entry_do: called CC=6 SCAR=17.9
Pod undocumented
89
90 14 A: foreach my $primary_key (keys %{$self->_structure}) {
91 27 foreach my $secondary_key (keys %{$self->_structure->{$primary_key}}) {
92 45 foreach my $entry (@{$self->_structure->{$primary_key}->{$secondary_key}}) {
93 304 my $return_code = $block->($entry);
94 304 ▶ last A if (defined $return_code and $return_code eq 'break_loop');
Branch: 1 branch
BranchTrueFalseTotal
if defined $return_code and $return_code eq "break_loop" 1 303 304
Condition66%2/3
defined $return_code and $return_code eq "break_loop"
!ll&&!rl&&r
03031
MC/DC50%1/2
defined $return_code and $return_code eq "break_loop"
defined $return_code $return_code eq "break_loop"
Truth table66%2/3
A and B
A= defined $return_codeB= $return_code eq "break_loop"
ABresult
0X0
100
111
95 }
96 }
97 }
98 14 return 0;
99 }
100  
101 sub foreach_entry_on_secondary_key_do {
102 2 ▶ my ($self, $secondary_key, $block) = @_;
Subroutine foreach_entry_on_secondary_key_do: called CC=6 SCAR=18.4
Pod undocumented
103
104 2 A: foreach my $primary_key (keys %{$self->_structure}) {
105 4 ▶ next if not defined $self->_structure->{$primary_key}->{$secondary_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_structure->{$primary_key}{$secondary_key} 2 2 4
106 2 foreach my $entry (@{$self->_structure->{$primary_key}->{$secondary_key}}) {
107 6 my $return_code = $block->($entry);
108 6 ▶ last A if (defined $return_code and $return_code eq 'break_loop');
Branch: 1 branch
BranchTrueFalseTotal
if defined $return_code and $return_code eq "break_loop" 0 6 6
Condition33%1/3
defined $return_code and $return_code eq "break_loop"
!ll&&!rl&&r
060
MC/DC0%0/2
defined $return_code and $return_code eq "break_loop"
defined $return_code $return_code eq "break_loop"
Truth table33%1/3
A and B
A= defined $return_codeB= $return_code eq "break_loop"
ABresult
0X0
100
111
109 }
110 }
111 }
112  
113 sub add_entry {
114 1937 ▶ my ($self, $primary_key, $secondary_key, $entry) = @_;
Subroutine add_entry: called CC=2 SCAR=6.9
Pod undocumented
115
116 1937 ▶ unless (exists $self->_structure->{$primary_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_structure->{$primary_key}) 113 1824 1937
117 113 $self->_structure->{$primary_key} = {};
118 }
119 1937 push @{$self->_structure->{$primary_key}->{$secondary_key}}, $entry;
120
121 1937 $self->_inc_entries_count;
122 1937 $self->_unset_is_sorted;
123 }
124  
125 sub primary_keys {
126 4 ▶ my ($self) = @_;
Subroutine primary_keys: called CC=1 SCAR=0.0
Pod undocumented
127 4 return sort keys %{$self->_structure};
128 }
129  
130 sub secondary_keys_for_primary_key {
131 8 ▶ my ($self, $primary_key) = @_;
Subroutine secondary_keys_for_primary_key: called CC=1 SCAR=0.0
Pod undocumented
132 8 return sort keys %{$self->_structure->{$primary_key}};
133 }
134  
135 sub secondary_keys_for_all_primary_keys {
136 2 ▶ my ($self) = @_;
Subroutine secondary_keys_for_all_primary_keys: called CC=3 SCAR=11.0
Pod undocumented
137
138 2 my %secondary_keys;
139 2 foreach my $primary_key ($self->primary_keys) {
140 4 foreach my $secondary_key ($self->secondary_keys_for_primary_key($primary_key)) {
141 8 $secondary_keys{$secondary_key} = 1;
142 }
143 }
144 2 return (sort keys %secondary_keys);
145 }
146  
147 sub is_empty {
148 3 ▶ my ($self) = @_;
Subroutine is_empty: called CC=2 SCAR=6.9
Pod undocumented
149
150 3 ▶ if ($self->entries_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->entries_count == 0) { } 1 2 3
151 1 return 1;
152 }
153 else {
154 2 return 0;
155 }
156 }
157  
158 sub is_not_empty {
159 3 ▶ my ($self) = @_;
Subroutine is_not_empty: called CC=3 SCAR=11.0
Pod undocumented
160
161 3 ▶ if (defined $self->entries_count and $self->entries_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->entries_count and $self->entries_count > 0) { } 2 1 3
Condition66%2/3
defined $self->entries_count and $self->entries_count > 0
!ll&&!rl&&r
012
MC/DC50%1/2
defined $self->entries_count and $self->entries_count > 0
defined $self->entries_count $self->entries_count > 0
Truth table66%2/3
A and B
A= defined $self->entries_countB= $self->entries_count > 0
ABresult
0X0
100
111
162 2 return 1;
163 }
164 else {
165 1 return 0;
166 }
167 }
168  
169 sub sort_entries {
170 4 ▶ my ($self) = @_;
Subroutine sort_entries: called CC=4 SCAR=13.9
Pod undocumented
171
172 4 ▶ if ($self->is_not_sorted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_not_sorted) 3 1 4
173 3 foreach my $primary_key (keys %{$self->_structure}) {
174 6 foreach my $secondary_key (keys %{$self->_structure->{$primary_key}}) {
175 12 my $entries_ref = $self->_structure->{$primary_key}->{$secondary_key};
176 12 @$entries_ref = sort {$self->sorting_code_block->($a,$b)} @$entries_ref;
177 }
178 }
179 3 $self->_set_is_sorted();
180 }
181 }
182  
183 sub entries_ref_for_keys {
184 7 ▶ my ($self, $primary_key, $secondary_key) = @_;
Subroutine entries_ref_for_keys: called CC=2 SCAR=7.6
Pod undocumented
185
186 7 ▶ if (exists $self->_structure->{$primary_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->_structure->{$primary_key}) { } 7 0 7
187 7 return $self->_structure->{$primary_key}->{$secondary_key};
188 }
189 else {
190 0 return undef;
191 }
192 }
193  
194  
195 #######################################################################
196 ############################ Finalize #############################
197 #######################################################################
198 1 __PACKAGE__->meta->make_immutable;
199  
200 1 1;
« GenOO/Data/File/FASTA.pm ↑ Summary GenOO/Spliceable.pm »