EnumBits.pm

filter: Statementstmt 72.7% 40 / 55 Branchbran 33.3% 6 / 18 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 63.1% 60 / 95 CC 12 SCAR 18.1
CC
12
Cov
61%
to_description
12.0
to_display_default
8.6
to_display
6.7
CRAP 6.1
« FreezeNotify.pm ↑ Summary SignalBits.pm »
1 # Copyright 2010, 2011, 2012, 2014, 2024 Kevin Ryde
2  
3 # This file is part of Glib-Ex-ObjectBits.
4 #
5 # Glib-Ex-ObjectBits is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Glib-Ex-ObjectBits is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Glib-Ex-ObjectBits. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Glib::Ex::EnumBits;
19 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # uncomment this to run the ### lines
25 #use Smart::Comments;
26  
27 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 our @ISA = ('Exporter');
29 1 our @EXPORT_OK = qw(to_display
30 to_display_default
31 to_description);
32  
33 1 our $VERSION = 17;
34  
35 12 ▶sub to_display {
Subroutine to_display: called CC=5 SCAR=19.0
Pod documented
36 12 my ($enum_class, $nick) = @_;
37 ### EnumBits to_display(): "$enum_class $nick"
38  
39 12 ▶ if (@_ != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 0 12 12
40 0 croak 'EnumBits to_display() wrong number of arguments';
41 }
42 12 ▶ if (my $coderef = $enum_class->can('EnumBits_to_display')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = $enum_class->can("EnumBits_to_display")) 0 12 12
43 ### $coderef
44 0 ▶ if (defined (my $str = $enum_class->$coderef($nick))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = $enum_class->$coderef($nick))) 0 0 0
45 0 return $str;
46 }
47 }
48 12 ▶ if (defined (my $str = do {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $str = do { no strict 'refs'; do { "${enum_class}::EnumBits_to_display" }->{$nick} })) 0 12 12
49 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 12 ${"${enum_class}::EnumBits_to_display"}{$nick}
51 })) {
52 0 return $str;
53 }
54 12 return to_display_default ($enum_class, $nick);
55 }
56  
57 24 ▶sub to_display_default {
Subroutine to_display_default: called CC=6 SCAR=21.5
Pod documented
58 24 my ($enum_class, $nick) = @_;
59 ### EnumBits to_display_default(): $nick
60  
61 24 ▶ if (@_ != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 0 24 24
62 # it's easy to forget the $enum_class parameter, guard against that ...
63 0 croak 'EnumBits to_display_default() wrong number of arguments';
64 }
65
66 24 ▶ if ($nick =~ /^([-_ ]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nick =~ /^([-_ ]+)$/) 0 24 24
67 # consists entirely of separators, eg "--"
68 # preserve something non-empty
69 0 $nick =~ s/^\s+//; # leading whitespace
70 0 $nick =~ s/\s+$//; # trailing whitespace
71 0 return $nick;
72 }
73  
74 my $str = join (' ',
75 24 map {ucfirst}
76 split(/[-_ ]+
77 |(?<=[^[:upper:][:digit:]])(?=\d) # before a digit
78 |(?<=\d)(?=\D) # after a digit
79 |(?<=[[:lower:]])(?=[[:upper:]])
80 |(?<=[[:upper:]])(?=[[:upper:]][[:lower:]])
81 /x,
82 $nick));
83 24 ▶ if (defined $enum_class
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enum_class and defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} }) and "Locale::Messages"->can("dgettext")) 0 24 24
Condition33%2/6
defined $enum_class and defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} }) and "Locale::Messages"->can("dgettext")
!ll&&!rl&&r
2400
defined $enum_class and defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} })
!ll&&!rl&&r
0240
MC/DC0%0/3
defined $enum_class and defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} }) and "Locale::Messages"->can("dgettext")
defined $enum_class defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} }) "Locale::Messages"->can("dgettext")
Truth table25%1/4
A and B and C
A= defined $enum_classB= defined(my $textdomain = do { no strict 'refs'; ${"${enum_class}::EnumBits_textdomain";} })C= "Locale::Messages"->can("dgettext")
ABCresult
0XX0
10X0
1100
1111
84 && defined (my $textdomain = do {
85 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 24 ${"${enum_class}::EnumBits_textdomain"}
87 })
88 && Locale::Messages->can('dgettext')) {
89 0 $str = Locale::Messages::dgettext ($textdomain, $str);
90 }
91 24 return $str;
92 }
93  
94 0 ▶sub to_description {
Subroutine to_description: not called CC=3 SCAR=24.8
Pod documented
95 0 my ($enum_class, $nick) = @_;
96 0 ▶ if (@_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ < 2) 0 0 0
97 0 croak "Not enough arguments for EnumBits to_description()";
98 }
99 0 ▶ if (my $coderef = $enum_class->can('EnumBits_to_description')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = $enum_class->can("EnumBits_to_description")) 0 0 0
100 0 return $enum_class->$coderef($nick);
101 }
102 0 return undef;
103 }
104  
105 1 1;
106 __END__
« FreezeNotify.pm ↑ Summary SignalBits.pm »