| 1 | 6 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Data::Conveyor::Charset::ViaHash; | ||||||||||
| 6 | 6 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 6 | $Data::Conveyor::Charset::ViaHash::VERSION = '1.103130'; | |||||||||
| 8 | } | ||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||
| 10 | |||||||||||
| 11 | 6 | ▶ | use charnames ':full'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 6 | ▶ | use parent 'Data::Conveyor::Charset'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 6 | __PACKAGE__->mk_constructor(qw(new))->mk_hash_accessors(qw(character_cache)) | |||||||||
| 14 | ->mk_scalar_accessors(qw(valid_string_re_cache)); | ||||||||||
| 15 | 0 | ▶ | sub CHARACTERS { () } | ||||||||
|
Subroutine
CHARACTERS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub get_characters { | ||||||||
|
Subroutine
get_characters: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 18 | 0 | my $self = shift; | |||||||||
| 19 | 0 | ▶ | unless ($self->character_cache_keys) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | my $characters = $self->every_hash('CHARACTERS'); | |||||||||
| 21 | |||||||||||
| 22 | # Convert the hash values to their actual Unicode character | ||||||||||
| 23 | # equivalent. For defining a character, we accept Unicode character | ||||||||||
| 24 | # names (the "..." part of the "\N{...}" notation) or hex code points | ||||||||||
| 25 | # (indicated by a leading "0x"; useful for characters that don't have | ||||||||||
| 26 | # a name). | ||||||||||
| 27 | 0 | for (values %$characters) { | |||||||||
| 28 | 0 | ▶ | next if utf8::is_utf8($_); # don't convert the already converted | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | ▶ | if (/^0x(.*)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | $_ = sprintf '%c' => hex($1); | |||||||||
| 31 | } else { | ||||||||||
| 32 | 0 | $_ = sprintf '%c' => charnames::vianame($_); | |||||||||
| 33 | } | ||||||||||
| 34 | 0 | utf8::upgrade($_); | |||||||||
| 35 | } | ||||||||||
| 36 | 0 | $self->character_cache(%$characters); | |||||||||
| 37 | } | ||||||||||
| 38 | 0 | return $self->character_cache; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub get_character_names { | ||||||||
|
Subroutine
get_character_names: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | 0 | my %characters = $self->get_characters; | |||||||||
| 44 | 0 | my @names = keys %characters; | |||||||||
| 45 | 0 | ▶ | wantarray ? @names : \@names; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub get_character_values { | ||||||||
|
Subroutine
get_character_values: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 49 | 0 | my $self = shift; | |||||||||
| 50 | 0 | my %characters = $self->get_characters; | |||||||||
| 51 | 0 | my @values = values %characters; | |||||||||
| 52 | 0 | ▶ | wantarray ? @values : \@values; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub is_valid_string { | ||||||||
|
Subroutine
is_valid_string: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 56 | 0 | my ($self, $string) = @_; | |||||||||
| 57 | 0 | ▶ | unless (defined $self->valid_string_re_cache) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | # escape critical characters so they're not interpreted as special | ||||||||||
| 60 | # characters in the regex. | ||||||||||
| 61 | my $chars = join '', | ||||||||||
| 62 | 0 | ▶ | map { m{^[\-.+*?()\[\]/\\]$} ? sprintf("\\%s", $_) : $_; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | $self->get_character_values; | ||||||||||
| 64 | 0 | $self->valid_string_re_cache(qr/^[$chars]+$/); | |||||||||
| 65 | } | ||||||||||
| 66 | 0 | $string =~ $self->valid_string_re_cache; | |||||||||
| 67 | } | ||||||||||
| 68 | 6 | 1; | |||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||