| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||