| 1 | package Types::Encodings; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | $Types::Encodings::AUTHORITY = 'cpan:TOBYINK'; | |||||||||
| 9 | 1 | $Types::Encodings::VERSION = '0.003'; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Type::Library -base, -declare => qw( Str Bytes Chars ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Type::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Types::Standard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | our $SevenBitSafe = qr{^[\x00-\x7F]*$}sm; | |||||||||
| 17 | |||||||||||
| 18 | 1 | declare Str, | |||||||||
| 19 | as Types::Standard::Str; | ||||||||||
| 20 | |||||||||||
| 21 | declare Bytes, | ||||||||||
| 22 | as Str, | ||||||||||
| 23 | 8 | ▶ | where { !utf8::is_utf8($_) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 33 | ▶ | inline_as { sprintf '(%s) && %s', Str->inline_check($_), "!utf8::is_utf8($_)" }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | declare Chars, | ||||||||||
| 27 | as Str, | ||||||||||
| 28 | 7 | ▶ | where { utf8::is_utf8($_) or $_ =~ $Types::Encodings::SevenBitSafe }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 29 | 31 | ▶ | inline_as { sprintf '(%s) && (%s)', Str->inline_check($_), "utf8::is_utf8($_) or $_ =~ \$Types::Encodings::SevenBitSafe" }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | declare_coercion Decode => to_type Chars, { | ||||||||||
| 32 | 4 | ▶ | coercion_generator => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 33 | 4 | my ($self, $target, $encoding) = @_; | |||||||||
| 34 | 4 | require Encode; | |||||||||
| 35 | 4 | ▶ | Encode::find_encoding($encoding) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | or _croak("Parameter \"$encoding\" for Decode[`a] is not an encoding supported by this version of Perl"); | ||||||||||
| 37 | 4 | require B; | |||||||||
| 38 | 4 | $encoding = B::perlstring($encoding); | |||||||||
| 39 | 4 | return (Bytes, qq{ Encode::decode($encoding, \$_) }); | |||||||||
| 40 | }, | ||||||||||
| 41 | 1 | }; | |||||||||
| 42 | |||||||||||
| 43 | declare_coercion Encode => to_type Bytes, { | ||||||||||
| 44 | 4 | ▶ | coercion_generator => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 45 | 4 | my ($self, $target, $encoding) = @_; | |||||||||
| 46 | 4 | require Encode; | |||||||||
| 47 | 4 | ▶ | Encode::find_encoding($encoding) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | or _croak("Parameter \"$encoding\" for Encode[`a] is not an encoding supported by this version of Perl"); | ||||||||||
| 49 | 4 | require B; | |||||||||
| 50 | 4 | $encoding = B::perlstring($encoding); | |||||||||
| 51 | 4 | return (Chars, qq{ Encode::encode($encoding, \$_) }); | |||||||||
| 52 | }, | ||||||||||
| 53 | 1 | }; | |||||||||
| 54 | |||||||||||
| 55 | 1 | 1; | |||||||||
| 56 | |||||||||||
| 57 | __END__ | ||||||||||