blib/lib/Sub/CharacterProperties.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 93.1% 54 / 58 CC 7 SCAR 10.2
CC
7
Cov
92%
get_ranges
4.2
as_code
4.0
BEGIN
1.0
CRAP 2.8
↑ Summary
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Sub::CharacterProperties;
6 2 our $VERSION = '1.100860';
7 # ABSTRACT: Support for user-defined character properties
8 2 ▶use Number::Rangify 'rangify';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use parent 'Class::Accessor::Complex';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 __PACKAGE__
12 ->mk_new
13 ->mk_array_accessors(qw(characters));
14  
15 1 ▶sub get_ranges {
Subroutine get_ranges: called CC=4 SCAR=14.2
Pod documented
16 1 my $self = shift;
17  
18 # Convert the values to their actual Unicode character equivalent. For
19 # defining a character, we accept Unicode character names (the "..." part
20 # of the "\N{...}" notation) or hex code points (indicated by a leading
21 # "0x"; useful for characters that don't have a name).
22 1 my @characters;
23 1 for ($self->characters) {
24 70 ▶ if (/^0x(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^0x(.*)$/) { } 0 70 70
25 0 push @characters => sprintf '%c' => hex($1);
26 } else {
27 70 push @characters => sprintf '%c' => charnames::vianame($_);
28 }
29 70 utf8::upgrade($_);
30 }
31 1 my @ranges = rangify(map { ord($_) } @characters);
32 1 ▶ wantarray ? @ranges : \@ranges;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
33 }
34  
35 1 ▶sub as_code {
Subroutine as_code: called CC=4 SCAR=13.9
Pod documented
36 1 my ($self, $name) = @_;
37 1 ▶ $name = 'InFoo' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
38 1 my $code = "sub $name { <<'END' }\n";
39 1 for my $range ($self->get_ranges) {
40 7 my ($lower, $upper) = $range->Size;
41 7 ▶ if ($lower == $upper) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lower == $upper) { } 3 4 7
42 3 $code .= sprintf "%X\n", $lower;
43 } else {
44 4 $code .= sprintf "%X %X\n", $lower, $upper;
45 }
46 }
47 1 $code .= "END\n";
48 1 $code;
49 }
50 2 1;
51  
52  
53 __END__
↑ Summary