blib/lib/StorageDisplay/Data/Elem.pm

filter: Statementstmt 87.6% 114 / 130 Branchbran 80.9% 34 / 42 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.8% 23 / 24 Podpod 0.0% 0 / 12 totaltotal 80.8% 173 / 214 CC 25 SCAR 16.9
CC
25
Cov
85%
statecolor
10.7
disp_size
10.1
__ANON__
6.0
CRAP 5.4
« blib/lib/StorageDisplay/Role.pm ↑ Summary blib/lib/StorageDisplay/Data/RAID.pm »
1 #
2 # This file is part of StorageDisplay
3 #
4 # This software is copyright (c) 2014-2023 by Vincent Danjean.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 package StorageDisplay::Data::Elem;
13 # ABSTRACT: Handle something that will be displayed and can be linked
14 # from/to as a tree for StorageDisplay
15  
16 10 our $VERSION = '2.06'; # VERSION
17  
18 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use namespace::sweep;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 10 ▶use StorageDisplay::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 ▶use Object::ID;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 10 with (
26 "StorageDisplay::Role::Iterable"
27 => {
28 iterable => "StorageDisplay::Data::Elem",
29 name => "Recursive",
30 },
31 "StorageDisplay::Role::Style::Base::Elem"
32 );
33  
34 has 'consume' => (
35 is => 'ro',
36 isa => 'ArrayRef[StorageDisplay::Block]',
37 traits => [ 'Array' ],
38 178 ▶ default => sub { return []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 10 lazy => 1,
40 handles => {
41 'consumeBlock' => 'push',
42 'consumedBlocks' => 'elements',
43 }
44 );
45  
46 has 'provide' => (
47 is => 'ro',
48 isa => 'ArrayRef[StorageDisplay::Block]',
49 traits => [ 'Array' ],
50 489 ▶ default => sub { return []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 10 lazy => 1,
52 handles => {
53 'provideBlock' => 'push',
54 'allProvidedBlocks' => 'elements',
55 },
56 init_arg => undef,
57 );
58  
59 430 ▶around 'provideBlock' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
60 430 my $orig = shift;
61 430 my $self = shift;
62  
63 430 for my $b (@_) {
64 430 $b->providedBy($self);
65 }
66 #print STDERR "INFO ", $self->name, " : provides ", map { $_->name } (@_);
67 #print STDERR "\n";
68 430 return $self->$orig(@_);
69 10 };
70  
71 #sub BUILD {
72 # my $self = shift;
73 # my $args = shift;
74 #
75 # print STDERR "INFO: ", $self->name, " : consumes ",
76 # join(', ', map { $_->name } ($self->consumedBlocks)), "\n";
77 # return $self;
78 #}
79  
80 829 ▶sub has_parent {
Subroutine has_parent: called CC=1 SCAR=0.0
Pod undocumented
81 829 my $self = shift;
82 829 return $self->nb_parents == 1;
83 }
84  
85 822 ▶sub parent {
Subroutine parent: called CC=2 SCAR=7.6
Pod undocumented
86 822 my $self = shift;
87 822 ▶ if ($self->nb_parents != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nb_parents != 1) 0 822 822
88 0 croak "Unkown parent requested for ".$self->label;
89 }
90 822 return ($self->parents)[0];
91 };
92  
93 10 has 'label' => (
94 is => 'rw',
95 isa => 'Str',
96 required => 0,
97 default => "NO LABEL",
98 );
99  
100 1051 ▶sub disp_size {
Subroutine disp_size: called CC=10 SCAR=23.2
Pod undocumented
101 1051 my $self = shift;
102 1051 my $size = shift;
103 1051 my $unit = 'B';
104 1051 my $d=2;
105 #print STDERR "\n\ninit size=$size\n";
106 {
107 10 ▶ use bigrat;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 1051 my $divide = 1;
109 1051 ▶ if ($size >= 1024) { $unit = 'kiB'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [1024], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 1035 16 1051
110 1051 ▶ if ($size >= 1048576) { $unit = 'MiB'; $divide *= 1024; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [1048576], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 983 68 1051
111 1051 ▶ if ($size >= 1073741824) { $unit = 'GiB'; $divide *= 1024; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [73741824,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 857 194 1051
112 1051 ▶ if ($size >= 1099511627776) { $unit = 'TiB'; $divide *= 1024; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [511627776,1099], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 238 813 1051
113 0 ▶ if ($size >= 1125899906842624) { $unit = 'PiB'; $divide *= 1024; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [906842624,1125899], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 0 1051 1051
114 0 ▶ if ($size >= 1152921504606846976) { $unit = 'EiB'; $divide *= 1024; }
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [606846976,152921504,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 0 1051 1051
115  
116 1051 ▶ if ($unit eq 'B') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'B') { } 16 1035 1051
117 16 return "$size B";
118 } else {
119 1035 $size /= $divide;
120 }
121 1035 $size = $size * 1000 / 1024;
122 1035 ▶ if ($size >= 10000) { $d = 1;}
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [10000], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 701 334 1035
123 1035 ▶ if ($size >= 100000) { $d = 0;}
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= bless( {"_d" => bless( [1], 'Math::BigInt::Calc' ),"_n" => bless( [100000], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigRat' )) 404 631 1035
124 #print STDERR "size=$size ", ref($size), "\n";
125 1035 $size=int($size/10**(3-$d)+0.5)*10**(3-$d);
126 #print STDERR "size=$size ", ref($size), "\n";
127 1035 $size = $size->numify();
128 }
129 1035 return sprintf("%.$d"."f $unit", $size/1000);
130 }
131  
132 738 ▶sub statecolor {
Subroutine statecolor: called CC=10 SCAR=23.7
Pod undocumented
133 738 my $self = shift;
134 738 my $state = shift;
135  
136 738 ▶ if ($state eq "free") {
Branch: 9 branches
BranchTrueFalseTotal
if ($state eq 'free') { } 104 634 738
elsif ($state eq 'ok') { } 26 608 634
elsif ($state eq 'used') { } 370 238 608
elsif ($state eq 'busy') { } 134 104 238
elsif ($state eq 'unused') { } 0 104 104
elsif ($state eq 'unknown') { } 42 62 104
elsif ($state eq 'special') { } 40 22 62
elsif ($state eq 'warning') { } 0 22 22
elsif ($state eq 'error') { } 0 22 22
137 104 return "green";
138 } elsif ($state eq "ok") {
139 26 return "green";
140 } elsif ($state eq "used") {
141 370 return "yellow";
142 } elsif ($state eq "busy") {
143 134 return "pink";
144 } elsif ($state eq "unused") {
145 0 return "white";
146 } elsif ($state eq "unknown") {
147 42 return "lightgrey";
148 } elsif ($state eq "special") {
149 40 return "mediumorchid1";
150 } elsif ($state eq "warning") {
151 0 return "orange";
152 } elsif ($state eq "error") {
153 0 return "red";
154 } else {
155 22 return "red";
156 }
157 }
158  
159 756 ▶sub dname {
Subroutine dname: called CC=1 SCAR=0.0
Pod undocumented
160 756 my $self = shift;
161 756 return $self->name;
162 }
163  
164 has 'linkkind' => (
165 is => 'ro',
166 isa => 'Str',
167 required => 1,
168 lazy => 1,
169 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
170 0 my $self = shift;
171 0 my $kind = ref($self);
172 0 $kind =~ s/^StorageDisplay::Data:://;
173 0 ▶ if ($self->has_parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_parent) 0 0 0
174 0 my $pkind = ref($self->parent);
175 0 $pkind =~ s/^StorageDisplay::Data:://;
176 0 $kind =~ s/^$pkind//;
177 }
178 0 return $kind;
179 },
180 10 );
181  
182 1501 ▶sub rawlinkname {
Subroutine rawlinkname: called CC=1 SCAR=0.0
Pod undocumented
183 1501 my $self = shift;
184 1501 return $self->fullname;
185 }
186  
187 1236 ▶sub linkname {
Subroutine linkname: called CC=1 SCAR=0.0
Pod undocumented
188 1236 my $self = shift;
189 1236 return '"'.$self->rawlinkname.'"';
190 }
191  
192 665 ▶sub newElem {
Subroutine newElem: called CC=1 SCAR=0.0
Pod undocumented
193 665 my $self = shift;
194 665 my $baseclass = shift;
195  
196 665 my $class = 'StorageDisplay::Data::'.$baseclass;
197 665 return $class->new(@_);
198 }
199  
200 352 ▶sub newChild {
Subroutine newChild: called CC=1 SCAR=0.0
Pod undocumented
201 352 my $self = shift;
202  
203 352 my $child = $self->newElem(@_);
204 352 $self->addChild($child);
205  
206 352 return $child;
207 }
208  
209 818 ▶sub pushDotText {
Subroutine pushDotText: called CC=2 SCAR=7.0
Pod undocumented
210 818 my $self = shift;
211 818 my $text = shift;
212 818 ▶ my $t = shift // "\t";
Condition50%1/2
shift() // "\t"
l!l
8180
MC/DC0%0/1
shift() // "\t"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
213  
214 818 my @pushed = map { $t.$_ } @_;
215 818 push @{$text}, @pushed;
216 }
217  
218 14 ▶sub dotSubNodes {
Subroutine dotSubNodes: called CC=3 SCAR=11.0
Pod undocumented
219 14 my $self = shift;
220 14 ▶ my $t = shift // "\t";
Condition50%1/2
shift() // "\t"
l!l
140
MC/DC0%0/1
shift() // "\t"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
221 14 my @text=();
222 14 my $it = $self->iterator(recurse => 0);
223 14 ▶ while (defined(my $e=$it->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = $it->next)) 124 14 138
224 124 push @text, $e->dotNode($t);
225 }
226 14 return @text;
227 }
228  
229 526 ▶sub dotLinks {
Subroutine dotLinks: called CC=1 SCAR=0.0
Pod undocumented
230 526 my $self = shift;
231 526 return ();
232 }
233  
234 10 1;
235  
236 __END__
« blib/lib/StorageDisplay/Role.pm ↑ Summary blib/lib/StorageDisplay/Data/RAID.pm »