Tools/EUtilities/Summary/Item.pm

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