| 1 | package Unicode::Block::Item; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # Pragmas. | ||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | # Modules. | ||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use Text::CharWidth qw(mbwidth); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use Unicode::Char; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | # Constants. | ||||||||||||||||||||||||||||||||||||
| 15 | 14 | Readonly::Scalar our $SPACE => q{ }; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | # Version. | ||||||||||||||||||||||||||||||||||||
| 18 | 14 | our $VERSION = 0.03; | |||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | # Constructor. | ||||||||||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||||||||||
| 22 | 23 | ▶ | my ($class, @params) = @_; | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | # Create object. | ||||||||||||||||||||||||||||||||||||
| 25 | 23 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | # Hexadecimal number. | ||||||||||||||||||||||||||||||||||||
| 28 | 23 | $self->{'hex'} = undef; | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | # Length of hex number. | ||||||||||||||||||||||||||||||||||||
| 31 | 23 | $self->{'hex_length'} = 4; | |||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | # Process parameters. | ||||||||||||||||||||||||||||||||||||
| 34 | 23 | set_params($self, @params); | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | # Check hex number. | ||||||||||||||||||||||||||||||||||||
| 37 | 21 | ▶ | if (! defined $self->{'hex'}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 38 | 1 | err "Parameter 'hex' is required."; | |||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||
| 40 | 20 | ▶ | if (! $self->_is_hex) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 41 | 1 | err "Parameter 'hex' isn't hexadecimal number."; | |||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | # Object. | ||||||||||||||||||||||||||||||||||||
| 45 | 19 | return $self; | |||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | # Get hex base number. | ||||||||||||||||||||||||||||||||||||
| 49 | sub base { | ||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
base: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $base = substr $self->hex, 0, -1; | |||||||||||||||||||||||||||||||||||
| 52 | 1 | return 'U+'.$base.'x'; | |||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | # Get character. | ||||||||||||||||||||||||||||||||||||
| 56 | sub char { | ||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
char: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | # Create object. | ||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | if (! exists $self->{'u'}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 11 | $self->{'u'} = Unicode::Char->new; | |||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | # Get char. | ||||||||||||||||||||||||||||||||||||
| 65 | 12 | my $char = $self->{'u'}->u($self->{'hex'}); | |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | # 'Non-Spacing Mark' and 'Enclosing Mark'. | ||||||||||||||||||||||||||||||||||||
| 68 | 12 | ▶ | if ($char =~ m/\p{Mn}/ms || $char =~ m/\p{Me}/ms) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$char =~ /\p{Mn}/ms or $char =~ /\p{Me}/ms
MC/DC100%2/2
$char =~ /\p{Mn}/ms or $char =~ /\p{Me}/ms
$char =~ /\p{Mn}/ms
$char =~ /\p{Me}/ms
Truth table100%3/3
A or B
A= $char =~ /\p{Mn}/msB= $char =~ /\p{Me}/ms
| |||||||||||||||||||||||||||||||||||||
| 69 | 4 | $char = $SPACE.$char; | |||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | # Control. | ||||||||||||||||||||||||||||||||||||
| 72 | } elsif ($char =~ m/\p{Cc}/ms) { | ||||||||||||||||||||||||||||||||||||
| 73 | 1 | $char = $SPACE; | |||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | # Not Assigned. | ||||||||||||||||||||||||||||||||||||
| 76 | } elsif ($char =~ m/\p{Cn}/ms) { | ||||||||||||||||||||||||||||||||||||
| 77 | 2 | $char = $SPACE; | |||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | 12 | return $char; | |||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | # Get hex number. | ||||||||||||||||||||||||||||||||||||
| 84 | sub hex { | ||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 86 | return sprintf '%0'.$self->{'hex_length'}.'x', | ||||||||||||||||||||||||||||||||||||
| 87 | 4 | CORE::hex $self->{'hex'}; | |||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | # Get last hex number. | ||||||||||||||||||||||||||||||||||||
| 91 | sub last_hex { | ||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
last_hex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 93 | 1 | return substr $self->{'hex'}, -1; | |||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | # Get character width. | ||||||||||||||||||||||||||||||||||||
| 97 | sub width { | ||||||||||||||||||||||||||||||||||||
| 98 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
width: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 99 | 7 | ▶ | if (! exists $self->{'_width'}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 100 | 6 | $self->{'_width'} = mbwidth($self->char); | |||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | if ($self->{'_width'} == -1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 102 | 2 | $self->{'_width'} = 1; | |||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | 7 | return $self->{'_width'}; | |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||
| 108 | # Check for hex number. | ||||||||||||||||||||||||||||||||||||
| 109 | sub _is_hex { | ||||||||||||||||||||||||||||||||||||
| 110 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_is_hex: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||
| 111 | 20 | ▶ | if ($self->{'hex'} !~ m/^[0-9a-fA-F]+$/ims) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 112 | 1 | return 0; | |||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||
| 114 | 19 | my $int = CORE::hex $self->{'hex'}; | |||||||||||||||||||||||||||||||||||
| 115 | 19 | ▶ | if (! defined $int) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 116 | 0 | return 0; | |||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||
| 118 | 19 | my $hex = sprintf '%x', $int; | |||||||||||||||||||||||||||||||||||
| 119 | 19 | my $value = lc $self->{'hex'}; | |||||||||||||||||||||||||||||||||||
| 120 | 19 | $value =~ s/^0*//ms; | |||||||||||||||||||||||||||||||||||
| 121 | 19 | ▶ | if ($value eq '') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 122 | 2 | $value = 0; | |||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||
| 124 | 19 | ▶ | if ($hex ne $value) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 125 | 0 | return 0; | |||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||
| 127 | 19 | return 1; | |||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | 14 | 1; | |||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||