| 1 | package Types::CLike; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use v5.8.8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.91'; # VERSION | |||||||||
| 8 | # ABSTRACT: C-like data types for Moo(se) | ||||||||||
| 9 | |||||||||||
| 10 | 2 | our @EXPORT_OK = (); | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Type::Library -base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use Types::Numbers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | my $meta = __PACKAGE__->meta; | |||||||||
| 16 | |||||||||||
| 17 | # All of these types are just aliases of parameterized parents | ||||||||||
| 18 | 182 | ▶ | sub __alias_subtype { | ||||||||
|
Subroutine
__alias_subtype: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 182 | $meta->add_type( | |||||||||
| 20 | name => $_[0], | ||||||||||
| 21 | parent => $_[1], | ||||||||||
| 22 | library => __PACKAGE__, | ||||||||||
| 23 | ); | ||||||||||
| 24 | }; | ||||||||||
| 25 | |||||||||||
| 26 | 14 | ▶ | sub __integer_builder { | ||||||||
|
Subroutine
__integer_builder: called CC=3 SCAR=11.0
| |||||||||||
| 27 | 14 | my ($bits, $signed_names, $unsigned_names) = @_; | |||||||||
| 28 | |||||||||||
| 29 | 14 | __alias_subtype($_, Types::Numbers::SignedInt[$bits]) for @$signed_names; | |||||||||
| 30 | 14 | __alias_subtype($_, Types::Numbers::UnsignedInt[$bits]) for @$unsigned_names; | |||||||||
| 31 | }; | ||||||||||
| 32 | |||||||||||
| 33 | 6 | ▶ | sub __money_builder { | ||||||||
|
Subroutine
__money_builder: called CC=2 SCAR=6.9
| |||||||||||
| 34 | 6 | my ($bits, $scale, $names) = @_; | |||||||||
| 35 | 6 | __alias_subtype($_, Types::Numbers::FixedBinary[$bits, $scale]) for @$names; | |||||||||
| 36 | }; | ||||||||||
| 37 | |||||||||||
| 38 | 16 | ▶ | sub __float_builder { | ||||||||
|
Subroutine
__float_builder: called CC=2 SCAR=6.9
| |||||||||||
| 39 | 16 | my ($bits, $ebits, $names) = @_; | |||||||||
| 40 | 16 | __alias_subtype($_, Types::Numbers::FloatBinary[$bits, $ebits]) for @$names; | |||||||||
| 41 | }; | ||||||||||
| 42 | |||||||||||
| 43 | 6 | ▶ | sub __decimal_builder { | ||||||||
|
Subroutine
__decimal_builder: called CC=2 SCAR=6.9
| |||||||||||
| 44 | 6 | my ($digits, $emax, $names) = @_; | |||||||||
| 45 | 6 | __alias_subtype($_, Types::Numbers::FloatDecimal[$digits, $emax]) for @$names; | |||||||||
| 46 | }; | ||||||||||
| 47 | |||||||||||
| 48 | 10 | ▶ | sub __char_builder { | ||||||||
|
Subroutine
__char_builder: called CC=2 SCAR=6.9
| |||||||||||
| 49 | 10 | my ($bits, $names) = @_; | |||||||||
| 50 | 10 | __alias_subtype($_, Types::Numbers::Char[$bits]) for @$names; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | ### Integer definitions ### | ||||||||||
| 54 | # being careful with char here... | ||||||||||
| 55 | __integer_builder( 4, [qw(SNibble SSemiOctet Int4 Signed4)], [qw(Nibble SemiOctet UInt4 Unsigned4)]), | ||||||||||
| 56 | __integer_builder( 8, [qw(SByte SOctet TinyInt Int8 Signed8)], [qw(Byte Octet UnsignedTinyInt UInt8 Unsigned8)]), | ||||||||||
| 57 | __integer_builder( 16, [qw(Short SmallInt Int16 Signed16)], [qw(UShort UnsignedSmallInt UInt16 Unsigned16)]), | ||||||||||
| 58 | __integer_builder( 24, [qw(MediumInt Int24 Signed24)], [qw(UnsignedMediumInt UInt24 Unsigned24)]), | ||||||||||
| 59 | __integer_builder( 32, [qw(Int Int32 Signed32)], [qw(UInt UnsignedInt UInt32 Unsigned32)]), | ||||||||||
| 60 | __integer_builder( 64, [qw(Long LongLong BigInt Int64 Signed64)], [qw(ULong ULongLong UnsignedBigInt UInt64 Unsigned64)]), | ||||||||||
| 61 | __integer_builder(128, [qw(SOctaWord SDoubleQuadWord Int128 Signed128)], [qw(OctaWord DoubleQuadWord UInt128 Unsigned128)]), | ||||||||||
| 62 | |||||||||||
| 63 | ### "Money" definitions ### | ||||||||||
| 64 | __money_builder( 32, 4, [qw(SmallMoney)]), | ||||||||||
| 65 | __money_builder( 64, 4, [qw(Money Currency)]), | ||||||||||
| 66 | __money_builder(128, 6, [qw(BigMoney)]), | ||||||||||
| 67 | |||||||||||
| 68 | ### Float definitions ### | ||||||||||
| 69 | __float_builder( 16, 4, [qw(ShortFloat)]), | ||||||||||
| 70 | __float_builder( 16, 5, [qw(Half Float16 Binary16)]), | ||||||||||
| 71 | __float_builder( 32, 8, [qw(Single Real Float Float32 Binary32)]), | ||||||||||
| 72 | __float_builder( 40, 8, [qw(ExtendedSingle Float40)]), | ||||||||||
| 73 | __float_builder( 64, 11, [qw(Double Float64 Binary64)]), | ||||||||||
| 74 | __float_builder( 80, 15, [qw(ExtendedDouble Float80)]), | ||||||||||
| 75 | __float_builder(104, 8, [qw(Decimal)]), | ||||||||||
| 76 | __float_builder(128, 15, [qw(Quadruple Quad Float128 Binary128)]), | ||||||||||
| 77 | |||||||||||
| 78 | ### Decimal definitions ### | ||||||||||
| 79 | __decimal_builder( 7, 96, [ 'Decimal32']), | ||||||||||
| 80 | __decimal_builder(16, 384, [ 'Decimal64']), | ||||||||||
| 81 | __decimal_builder(34, 6144, ['Decimal128']), | ||||||||||
| 82 | |||||||||||
| 83 | ### Char definitions ### | ||||||||||
| 84 | __char_builder( 8, [qw(Char Char8)]), | ||||||||||
| 85 | __char_builder(16, [qw(Char16)]), | ||||||||||
| 86 | __char_builder(32, [qw(Char32)]), | ||||||||||
| 87 | __char_builder(48, [qw(Char48)]), | ||||||||||
| 88 | __char_builder(64, [qw(Char64)]), | ||||||||||
| 89 | |||||||||||
| 90 | my %base_tags = ( | ||||||||||
| 91 | 'c' => [qw(Char Byte Short UShort Int UInt Long ULong Float Double ExtendedDouble)], | ||||||||||
| 92 | 12 | 'stdint' => [ map { ('Int'.$_, 'UInt'.$_) } (4,8,16,32,64,128) ], | |||||||||
| 93 | 'c#' => [qw(SByte Byte Char16 Short UShort Int UInt Long ULong Float Double Decimal)], | ||||||||||
| 94 | 6 | 'ieee754' => ['Binary16', map { ('Binary'.$_, 'Decimal'.$_) } (32,64,128) ], | |||||||||
| 95 | 'tsql' => [qw(TinyInt SmallInt Int BigInt SmallMoney Money Float64 Real)], | ||||||||||
| 96 | 2 | 'mysql' => [ (map { ($_, 'Unsigned'.$_) } qw(TinyInt SmallInt MediumInt Int BigInt)), qw(Float Double)], | |||||||||
| 97 | 'ansisql' => [qw(SmallInt Int Float Real Double)], | ||||||||||
| 98 | ); | ||||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | sub _exporter_expand_tag { | ||||||||
|
Subroutine
_exporter_expand_tag: not called CC=3 SCAR=24.8
| |||||||||||
| 101 | 0 | my $class = shift; | |||||||||
| 102 | 0 | my ($name, $value, $globals) = @_; | |||||||||
| 103 | |||||||||||
| 104 | 0 | my $p = ''; | |||||||||
| 105 | 0 | my $base_name = $name; | |||||||||
| 106 | 0 | ▶ | $base_name =~ s/^((?:is|assert|to)_|\+)// and $p = $1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | $base_tags{$base_name} and return map [ "$p$_" => $value ], @{ $base_tags{$base_name} }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | return $class->SUPER::_exporter_expand_tag(@_); | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 2 | 42; | |||||||||
| 114 | |||||||||||
| 115 | __END__ | ||||||||||