Tools/EUtilities/Summary/Item.pm

filter: Statementstmt 45.4% 60 / 132 Branchbran 34.0% 15 / 44 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 50.0% 15 / 30 Podpod 100% 21 / 21 totaltotal 45.9% 113 / 246 CC 34 SCAR 21.6
CC
34
Cov
41%
get_all_Items
30.0
next_Item
20.0
to_string
20.0
CRAP 8.7
« Tools/EUtilities/Info.pm ↑ Summary Tools/EUtilities/Summary.pm »
1 package Bio::Tools::EUtilities::Summary::Item;
2 4 $Bio::Tools::EUtilities::Summary::Item::VERSION = '1.77';
3 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use base qw(Bio::Root::Root Bio::Tools::EUtilities::EUtilDataI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Simple layered object for DocSum item data.
9 # AUTHOR: Chris Fields <cjfields@bioperl.org>
10 # OWNER: 2006-2013 Chris Fields
11 # LICENSE: Perl_5
12  
13  
14  
15 160 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
16 160 my ($class, @args) = @_;
17 160 my $self = $class->SUPER::new(@args);
18 160 my ($type) = $self->_rearrange(['DATATYPE'],@args);
19 160 ▶ $type ||= 'item';
Condition50%1/2
$type ||= "item"
l!l
1600
MC/DC0%0/1
$type ||= "item"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
20 160 $self->datatype($type);
21 160 $self->eutil('esummary');
22 160 $self->rewind('recursive');
23 160 return $self;
24 }
25  
26  
27 0 ▶sub get_ids {
Subroutine get_ids: not called CC=1 SCAR=6.9
Pod documented
28 0 my $self = shift;
29 0 return ($self->{'_id'});
30 }
31  
32  
33 9 ▶sub get_id {
Subroutine get_id: called CC=1 SCAR=0.0
Pod documented
34 9 my $self = shift;
35 9 return $self->{'_id'};
36 }
37  
38  
39 0 ▶sub next_ListItem {
Subroutine next_ListItem: not called CC=3 SCAR=24.8
Pod documented
40 0 my $self = shift;
41 0 ▶ unless ($self->{'_lists_it'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_lists_it"}) 0 0 0
42 0 my @lists = $self->get_ListItems;
43 # reset the structure iterator (required!)
44 0 ▶ delete $self->{'_structures_it'} if $self->{'_structures_it'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_structures_it"} 0 0 0
45 0 ▶ $self->{'_lists_it'} = sub {return shift @lists}
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 }
47 0 return $self->{'_lists_it'}->();
48 }
49  
50  
51 59 ▶sub get_ListItems {
Subroutine get_ListItems: called CC=2 SCAR=6.9
Pod documented
52 59 my $self = shift;
53 59 ▶ my @items = $self->get_type eq 'List' ? $self->get_subItems : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->get_type eq 'List' ? : 3 56 59
54 59 return @items;
55 }
56  
57  
58 0 ▶sub next_StructureItem {
Subroutine next_StructureItem: not called CC=2 SCAR=17.9
Pod documented
59 0 my $self = shift;
60 0 ▶ unless ($self->{'_structures_it'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_structures_it"}) 0 0 0
61 0 my @structs = $self->get_StructureItems;
62 0 ▶ $self->{'_structures_it'} = sub {return shift @structs}
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 }
64 0 return $self->{'_structures_it'}->();
65 }
66  
67  
68 18 ▶sub get_StructureItems {
Subroutine get_StructureItems: called CC=2 SCAR=7.1
Pod documented
69 18 my $self = shift;
70 18 ▶ my @items = $self->get_type eq 'Structure' ? $self->get_subItems : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->get_type eq 'Structure' ? : 18 0 18
71 18 return @items;
72 }
73  
74  
75 0 ▶sub next_subItem {
Subroutine next_subItem: not called CC=2 SCAR=17.9
Pod documented
76 0 my $self = shift;
77 0 ▶ unless ($self->{'_subitem_it'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_subitem_it"}) 0 0 0
78 0 my @structs = $self->get_subItems;
79 0 ▶ $self->{'_subitem_it'} = sub {return shift @structs}
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 }
81 0 return $self->{'_subitem_it'}->();
82 }
83  
84  
85 21 ▶sub get_subItems {
Subroutine get_subItems: called CC=2 SCAR=7.1
Pod documented
86 21 my $self = shift;
87 21 ▶ ref $self->{'_items'} ? return @{ $self->{'_items'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_items'} ? : 21 0 21
88 }
89  
90  
91 281 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod documented
92 281 my $self = shift;
93 281 return $self->{'_itemname'};
94 }
95  
96  
97 91 ▶sub get_type {
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
98 91 my $self = shift;
99 91 return $self->{'_itemtype'};
100 }
101  
102  
103 28 ▶sub get_content {
Subroutine get_content: called CC=1 SCAR=0.0
Pod documented
104 28 my $self = shift;
105 28 return $self->{'_itemcontent'};
106 }
107  
108  
109 160 ▶sub rewind {
Subroutine rewind: called CC=5 SCAR=20.2
Pod documented
110 160 my ($self, $request) = @_;
111 160 ▶ if ($request && $request eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request and $request eq "all") 0 160 160
Condition33%1/3
$request and $request eq "all"
!ll&&!rl&&r
01600
MC/DC0%0/2
$request and $request eq "all"
$request $request eq "all"
Truth table33%1/3
A and B
A= $requestB= $request eq "all"
ABresult
0X0
100
111
112 0 map {$_->rewind()} $self->get_ListItems;
113 }
114 160 ▶ delete $self->{"_lists_it"} if $self->{"_lists_it"};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_lists_it"} 0 160 160
115 160 ▶ delete $self->{"_structures_it"} if $self->{"_structures_it"};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_structures_it"} 0 160 160
116 }
117  
118  
119  
120 0 ▶sub next_Item {
Subroutine next_Item: not called CC=4 SCAR=30.0
Pod documented
121 0 my ($self, $request) = @_;
122 0 ▶ unless ($self->{"_items_it"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_items_it"}) 0 0 0
123 #my @items = $self->get_Items;
124 0 ▶ my @items = ($request && $request eq 'flatten') ?
Branch: 1 branch
BranchTrueFalseTotal
$request && $request eq 'flatten' ? : 0 0 0
Condition0%0/3
$request and $request eq "flatten"
!ll&&!rl&&r
000
MC/DC0%0/2
$request and $request eq "flatten"
$request $request eq "flatten"
Truth table0%0/3
A and B
A= $requestB= $request eq "flatten"
ABresult
0X0
100
111
125 $self->get_all_Items :
126 $self->get_Items ;
127 0 ▶ $self->{"_items_it"} = sub {return shift @items}
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 0 }
129 0 $self->{'_items_it'}->();
130 }
131  
132  
133 1 ▶sub get_Items {
Subroutine get_Items: called CC=2 SCAR=7.1
Pod documented
134 1 my $self = shift;
135 1 ▶ return ref $self->{'_items'} ? @{ $self->{'_items'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_items'} ? : 1 0 1
136 }
137  
138  
139 0 ▶sub get_all_Items {
Subroutine get_all_Items: not called CC=5 SCAR=34.0
Pod documented
140 0 my $self = shift;
141 0 ▶ unless ($self->{'_ordered_items'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_ordered_items"}) 0 0 0
142 0 for my $item ($self->get_Items) {
143 0 push @{$self->{'_ordered_items'}}, $item;
144 0 for my $ls ($item->get_ListItems) {
145 0 push @{$self->{'_ordered_items'}}, $ls;
146 0 for my $st ($ls->get_StructureItems) {
147 0 push @{$self->{'_ordered_items'}}, $st;
148 }
149 }
150 }
151 }
152 0 return @{$self->{'_ordered_items'}};
153 }
154  
155  
156 0 ▶sub get_all_names {
Subroutine get_all_names: not called CC=1 SCAR=6.9
Pod documented
157 0 my ($self) = @_;
158 0 my %tmp;
159 0 my @data = grep {!$tmp{$_}++}
160 0 map {$_->get_name} $self->get_all_Items;
161 0 return @data;
162 }
163  
164  
165 0 ▶sub get_Items_by_name {
Subroutine get_Items_by_name: not called CC=2 SCAR=17.9
Pod documented
166 0 my ($self, $key) = @_;
167 0 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
168 0 my @data = grep {$_->get_name eq $key}
169 $self->get_all_Items;
170 0 return @data;
171 }
172  
173  
174 0 ▶sub get_contents_by_name {
Subroutine get_contents_by_name: not called CC=2 SCAR=17.9
Pod documented
175 0 my ($self, $key) = @_;
176 0 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
177 0 my @data = map {$_->get_content}
178 0 grep {$_->get_name eq $key}
179 $self->get_all_Items;
180 0 return @data;
181 }
182  
183  
184 0 ▶sub get_type_by_name {
Subroutine get_type_by_name: not called CC=2 SCAR=17.9
Pod documented
185 0 my ($self, $key) = @_;
186 0 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
187 0 my ($it) = grep {$_->get_name eq $key} $self->get_all_Items;
188 0 return $it->get_type;
189 }
190  
191 # private data method
192  
193 160 ▶sub _add_data {
Subroutine _add_data: called CC=8 SCAR=20.9
194 160 my ($self, $data) = @_;
195 160 ▶ if ($data->{Item}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Item"}) 18 142 160
196 18 my $objtype = lc $data->{Type}.'_item';
197 18 ▶ $self->{'_id'} = $data->{Id} if exists $data->{Id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"Id"} 18 0 18
198 18 for my $sd (@{ $data->{Item} } ) {
199 96 ▶ $sd->{Id} = $data->{Id} if exists $data->{Id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"Id"} 96 0 96
200 96 my $subdoc = Bio::Tools::EUtilities::Summary::Item->new(
201 -datatype => $objtype,
202 -verbose => $self->verbose);
203 96 $subdoc->_add_data($sd);
204 96 push @{ $self->{'_items'} }, $subdoc;
205 }
206 }
207 160 for my $nm (qw(Type content Name)) {
208 480 ▶ $self->{'_item'.lc $nm} = $data->{$nm} if defined $data->{$nm};
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{$nm} 450 30 480
209 }
210 160 ▶ $self->{'_id'} = $data->{Id} if exists $data->{Id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"Id"} 160 0 160
211 }
212  
213  
214 # recursively called to grab subitems, then layer
215  
216 0 ▶sub to_string {
Subroutine to_string: not called CC=4 SCAR=30.0
Pod documented
217 0 my $self = shift;
218 0 ▶ my $level = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
219 # this is the field length for the initial data (spaces are padded in front)
220 0 my $pad = 20 - $level;
221 0 ▶ my $content = $self->get_content || '';
Condition0%0/2
$self->get_content || ''
l!l
00
MC/DC0%0/1
$self->get_content || ''
$self->get_content
Truth table0%0/2
A
A= $self->get_content
Aresult
11
00
222 0 my $string .= sprintf("%-*s%-*s%s\n",
223 $level, '',
224 $pad, $self->get_name(),
225 $self->_text_wrap(':',
226 ' ' x ($pad).':',
227 $content));
228 0 for my $sub ($self->get_subItems) {
229 0 $string .= $sub->to_string(4 + $level);
230 }
231 0 return $string;
232 }
233  
234 4 1;
235  
236 __END__
« Tools/EUtilities/Info.pm ↑ Summary Tools/EUtilities/Summary.pm »