| 1 | package Data::Petitcom::Resource::PRG; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use parent qw{ Data::Petitcom::Resource }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 4 | ▶ | use Encode (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | ▶ | use Unicode::Japanese; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 4 | ▶ | use Data::Petitcom::CharTBL qw{ dump_char load_char }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use Data::Petitcom::PTC; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 4 | ▶ | use bytes (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 4 | ▶ | use constant RESOUECE => 'PRG'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 4 | ▶ | use constant PTC_OFFSET_CODE => 0x18; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 4 | ▶ | use constant PTC_NAME => 'DPTC_PRG'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 2 | ▶ | sub save { | ||||||||||
|
Subroutine
save: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 19 | 2 | my $self = shift; | |||||||||||
| 20 | 2 | my %opts = @_; | |||||||||||
| 21 | 2 | ▶ | my $name = delete $opts{name} || PTC_NAME; | ||||||||||
|
Condition50%1/2
delete $opts{'name'} || 'DPTC_PRG'
MC/DC0%0/1
delete $opts{'name'} || 'DPTC_PRG'
delete $opts{'name'}
Truth table50%1/2
A
A= delete $opts{'name'}
| |||||||||||||
| 22 | 2 | my $encoding = delete $opts{encoding}; | |||||||||||
| 23 | 2 | my $ptc = $self->_create_ptc($name, $encoding); | |||||||||||
| 24 | 2 | return $ptc; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | sub load { | ||||||||||
|
Subroutine
load: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 28 | 2 | my $self = shift; | |||||||||||
| 29 | 2 | my ( $ptc, %opts ) = @_; | |||||||||||
| 30 | 2 | my $zenkaku = delete $opts{zenkaku}; | |||||||||||
| 31 | 2 | my $encoding = delete $opts{encoding}; | |||||||||||
| 32 | 2 | my $code = substr $ptc->data, PTC_OFFSET_CODE; | |||||||||||
| 33 | 2 | $self->data( _decode( $code, $zenkaku, $encoding ) ); | |||||||||||
| 34 | 2 | return $self; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | sub _create_ptc { | ||||||||||
|
Subroutine
_create_ptc: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||
| 39 | 2 | my ($name, $encoding) = @_; | |||||||||||
| 40 | 2 | my $ptc = Data::Petitcom::PTC->new( | |||||||||||
| 41 | resource => RESOUECE, | ||||||||||||
| 42 | name => $name, | ||||||||||||
| 43 | ); | ||||||||||||
| 44 | 2 | my $code = _encode( $self->data, $encoding ); | |||||||||||
| 45 | 2 | my $header_data = pack 'C*', 0x00, 0x00, 0x00, 0x00; | |||||||||||
| 46 | 2 | $header_data .= pack 'C*', 0x00, 0x00, 0x00, 0x00; | |||||||||||
| 47 | 2 | $header_data .= pack 'I', bytes::length( $code ); | |||||||||||
| 48 | 2 | $ptc->data( $header_data . $code ); | |||||||||||
| 49 | 2 | return $ptc; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 3 | ▶ | sub _encode { | ||||||||||
|
Subroutine
_encode: called CC=3 SCAR=11.0
| |||||||||||||
| 53 | 3 | my $code = shift; | |||||||||||
| 54 | 3 | my $encoding = shift; | |||||||||||
| 55 | 3 | ▶ | $code = ($encoding) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | ? Encode::find_encoding($encoding)->decode($code) | ||||||||||||
| 57 | : Encode::decode_utf8($code); | ||||||||||||
| 58 | 2 | $code = Unicode::Japanese->new($code)->hira2kata->z2h->getu; | |||||||||||
| 59 | 2 | $code =~ s/\r\n/\r/g; | |||||||||||
| 60 | 2 | $code =~ s/\n/\r/g; | |||||||||||
| 61 | 2 | my $encoded = ''; | |||||||||||
| 62 | 2 | for my $i ( 0 .. ( length($code) - 1 ) ) { | |||||||||||
| 63 | 40 | my $char = substr( $code, $i, 1 ); | |||||||||||
| 64 | 40 | $encoded .= dump_char($char); | |||||||||||
| 65 | } | ||||||||||||
| 66 | 2 | return $encoded; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 2 | ▶ | sub _decode { | ||||||||||
|
Subroutine
_decode: called CC=4 SCAR=14.6
| |||||||||||||
| 70 | 2 | my $binary = shift; | |||||||||||
| 71 | 2 | my ( $zenkaku, $encoding ) = @_; | |||||||||||
| 72 | 2 | my $decoded = ''; | |||||||||||
| 73 | 2 | for my $i ( 0 .. ( bytes::length($binary) - 1 ) ) { | |||||||||||
| 74 | 40 | my $byte = bytes::substr( $binary, $i, 1 ); | |||||||||||
| 75 | 40 | $decoded .= load_char($byte); | |||||||||||
| 76 | } | ||||||||||||
| 77 | 2 | ▶ | if ($zenkaku) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | # $decoded = Unicode::Japanese->new($decoded)->h2zKanaK->get; | ||||||||||||
| 79 | # $decoded = Unicode::Japanese->new($decoded)->h2z->get; | ||||||||||||
| 80 | 0 | $decoded = Unicode::Japanese->new($decoded)->h2zKanaK->h2z->getu; | |||||||||||
| 81 | } | ||||||||||||
| 82 | 2 | ▶ | if ($encoding) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | Encode::from_to( $decoded, 'utf8', $encoding ); | |||||||||||
| 84 | } | ||||||||||||
| 85 | 2 | return $decoded; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 4 | 1; | |||||||||||