| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package MaxMind::DB::Types; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 7 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 44 |  | 
| 4 | 2 |  |  | 2 |  | 6 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 59 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '0.040000'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 6 | use Carp qw( confess ); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 90 |  | 
| 9 | 2 |  |  | 2 |  | 7 | use Exporter qw( import ); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 34 |  | 
| 10 | 2 |  |  | 2 |  | 740 | use List::AllUtils; | 
|  | 2 |  |  |  |  | 19557 |  | 
|  | 2 |  |  |  |  | 95 |  | 
| 11 | 2 |  |  | 2 |  | 14 | use Scalar::Util (); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 27 |  | 
| 12 | 2 |  |  | 2 |  | 3522 | use Sub::Quote qw( quote_sub ); | 
|  | 2 |  |  |  |  | 4974 |  | 
|  | 2 |  |  |  |  | 117 |  | 
| 13 | 2 |  |  | 2 |  | 929 | use overload (); | 
|  | 2 |  |  |  |  | 675 |  | 
|  | 2 |  |  |  |  | 607 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our @EXPORT_OK = qw( | 
| 16 |  |  |  |  |  |  | ArrayRefOfStr | 
| 17 |  |  |  |  |  |  | Bool | 
| 18 |  |  |  |  |  |  | Decoder | 
| 19 |  |  |  |  |  |  | Epoch | 
| 20 |  |  |  |  |  |  | FileHandle | 
| 21 |  |  |  |  |  |  | HashRef | 
| 22 |  |  |  |  |  |  | HashRefOfStr | 
| 23 |  |  |  |  |  |  | Int | 
| 24 |  |  |  |  |  |  | Metadata | 
| 25 |  |  |  |  |  |  | Str | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | ## no critic (NamingConventions::Capitalization, ValuesAndExpressions::ProhibitImplicitNewlines) | 
| 29 |  |  |  |  |  |  | { | 
| 30 |  |  |  |  |  |  | my $t = quote_sub( | 
| 31 |  |  |  |  |  |  | q{ | 
| 32 |  |  |  |  |  |  | ( | 
| 33 |  |  |  |  |  |  | defined $_[0] | 
| 34 |  |  |  |  |  |  | && Scalar::Util::reftype( $_[0] ) eq 'ARRAY' | 
| 35 |  |  |  |  |  |  | && List::AllUtils::all( | 
| 36 |  |  |  |  |  |  | sub { defined $_ && !ref $_ }, | 
| 37 |  |  |  |  |  |  | @{ $_[0] } | 
| 38 |  |  |  |  |  |  | ) | 
| 39 |  |  |  |  |  |  | ) | 
| 40 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 41 |  |  |  |  |  |  | '%s is not an arrayref', | 
| 42 |  |  |  |  |  |  | $_[0] | 
| 43 |  |  |  |  |  |  | ); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | ); | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 2 |  |  | 2 | 0 | 12 | sub ArrayRefOfStr () { $t } | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | { | 
| 51 |  |  |  |  |  |  | my $t = quote_sub( | 
| 52 |  |  |  |  |  |  | q{ | 
| 53 |  |  |  |  |  |  | ( !defined $_[0] || $_[0] eq q{} || "$_[0]" eq '1' || "$_[0]" eq '0' ) | 
| 54 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 55 |  |  |  |  |  |  | '%s is not a boolean', | 
| 56 |  |  |  |  |  |  | $_[0] | 
| 57 |  |  |  |  |  |  | ); | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | ); | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 0 |  |  | 0 | 0 | 0 | sub Bool () { $t } | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | { | 
| 65 |  |  |  |  |  |  | my $t = _object_isa_type('MaxMind::DB::Reader::Decoder'); | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  | 0 | 0 | 0 | sub Decoder () { $t } | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | { | 
| 71 |  |  |  |  |  |  | my $t = quote_sub( | 
| 72 |  |  |  |  |  |  | q{ | 
| 73 |  |  |  |  |  |  | ( | 
| 74 |  |  |  |  |  |  | defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+$/ ) | 
| 75 |  |  |  |  |  |  | || ( Scalar::Util::blessed( $_[0] ) | 
| 76 |  |  |  |  |  |  | && ( $_[0]->isa('Math::UInt128') || $_[0]->isa('Math::BigInt') ) ) | 
| 77 |  |  |  |  |  |  | ) | 
| 78 |  |  |  |  |  |  | ) | 
| 79 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 80 |  |  |  |  |  |  | '%s is not an integer, a Math::UInt128 object, or a Math::BigInt object', | 
| 81 |  |  |  |  |  |  | $_[0] | 
| 82 |  |  |  |  |  |  | ); | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | ); | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 2 |  |  | 2 | 0 | 6 | sub Epoch () { $t } | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | { | 
| 90 |  |  |  |  |  |  | my $t = quote_sub( | 
| 91 |  |  |  |  |  |  | q{ | 
| 92 |  |  |  |  |  |  | (          ( defined $_[0] && Scalar::Util::openhandle( $_[0] ) ) | 
| 93 |  |  |  |  |  |  | || ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('IO::Handle') ) ) | 
| 94 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 95 |  |  |  |  |  |  | '%s is not a file handle', | 
| 96 |  |  |  |  |  |  | $_[0] | 
| 97 |  |  |  |  |  |  | ); | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  | ); | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 0 |  |  | 0 | 0 | 0 | sub FileHandle () { $t } | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | { | 
| 105 |  |  |  |  |  |  | my $t = quote_sub( | 
| 106 |  |  |  |  |  |  | q{ | 
| 107 |  |  |  |  |  |  | ( defined $_[0] && Scalar::Util::reftype( $_[0] ) eq 'HASH' ) | 
| 108 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 109 |  |  |  |  |  |  | '%s is not a hashref', | 
| 110 |  |  |  |  |  |  | $_[0] | 
| 111 |  |  |  |  |  |  | ); | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | ); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 0 |  |  | 0 | 0 | 0 | sub HashRef () { $t } | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | { | 
| 119 |  |  |  |  |  |  | my $t = quote_sub( | 
| 120 |  |  |  |  |  |  | q{ | 
| 121 |  |  |  |  |  |  | ( | 
| 122 |  |  |  |  |  |  | defined $_[0] | 
| 123 |  |  |  |  |  |  | && Scalar::Util::reftype( $_[0] ) eq 'HASH' | 
| 124 |  |  |  |  |  |  | && &List::AllUtils::all( | 
| 125 |  |  |  |  |  |  | sub { defined $_ && !ref $_ }, values %{ $_[0] } | 
| 126 |  |  |  |  |  |  | ) | 
| 127 |  |  |  |  |  |  | ) | 
| 128 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 129 |  |  |  |  |  |  | '%s is not a hashref of strings', | 
| 130 |  |  |  |  |  |  | $_[0] | 
| 131 |  |  |  |  |  |  | ); | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  | ); | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 2 |  |  | 2 | 0 | 4 | sub HashRefOfStr () { $t } | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | { | 
| 139 |  |  |  |  |  |  | my $t = quote_sub( | 
| 140 |  |  |  |  |  |  | q{ | 
| 141 |  |  |  |  |  |  | ( defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+$/ ) | 
| 142 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 143 |  |  |  |  |  |  | '%s is not a valid integer', | 
| 144 |  |  |  |  |  |  | $_[0] | 
| 145 |  |  |  |  |  |  | ); | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  | ); | 
| 148 |  |  |  |  |  |  |  | 
| 149 | 10 |  |  | 10 | 0 | 28 | sub Int () { $t } | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | { | 
| 153 |  |  |  |  |  |  | my $t = _object_isa_type('MaxMind::DB::Metadata'); | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 0 |  |  | 0 | 0 | 0 | sub Metadata () { $t } | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | { | 
| 159 |  |  |  |  |  |  | my $t = quote_sub( | 
| 160 |  |  |  |  |  |  | q{ | 
| 161 |  |  |  |  |  |  | ( defined $_[0] && !ref $_[0] ) | 
| 162 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( '%s is not a string', $_[0] ); | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  | ); | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 2 |  |  | 2 | 0 | 6 | sub Str () { $t } | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | sub _object_isa_type { | 
| 170 | 4 |  |  | 4 |  | 5 | my $class = shift; | 
| 171 |  |  |  |  |  |  |  | 
| 172 | 4 |  |  |  |  | 10 | return quote_sub( | 
| 173 |  |  |  |  |  |  | qq{ | 
| 174 |  |  |  |  |  |  | ( Scalar::Util::blessed( \$_[0] ) && \$_[0]->isa('$class') ) | 
| 175 |  |  |  |  |  |  | or MaxMind::DB::Types::_confess( | 
| 176 |  |  |  |  |  |  | '%s is not a $class object', | 
| 177 |  |  |  |  |  |  | \$_[0] | 
| 178 |  |  |  |  |  |  | ); | 
| 179 |  |  |  |  |  |  | } | 
| 180 |  |  |  |  |  |  | ); | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  | ## use critic | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | 
| 185 |  |  |  |  |  |  | sub _confess { | 
| 186 |  |  |  |  |  |  | ## no critic (Subroutines::ProhibitCallsToUnexportedSubs) | 
| 187 | 0 | 0 |  | 0 |  |  | confess sprintf( | 
| 188 |  |  |  |  |  |  | $_[0], | 
| 189 |  |  |  |  |  |  | defined $_[1] ? overload::StrVal( $_[1] ) : 'undef' | 
| 190 |  |  |  |  |  |  | ); | 
| 191 |  |  |  |  |  |  | } | 
| 192 |  |  |  |  |  |  | ## use critic | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | 1; |