Tools/EUtilities/Summary/Item.pm

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