| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | ### $coderef | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (defined (my $str = $enum_class->$coderef($nick))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | ▶ | if (defined (my $str = do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $enum_class and defined(my $textdomain = do {
no strict 'refs';
${"${enum_class}::EnumBits_textdomain";}
}) and "Locale::Messages"->can("dgettext")
defined $enum_class and defined(my $textdomain = do {
no strict 'refs';
${"${enum_class}::EnumBits_textdomain";}
})
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $enum_class->$coderef($nick); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||