| 1 | package Net::Works::Types; | ||||||||||
| 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 | our $VERSION = '0.22'; | |||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Carp qw( confess ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use Exporter qw( import ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use Scalar::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use Sub::Quote qw( quote_sub ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 4 | our @EXPORT_OK = qw( | |||||||||
| 14 | Int | ||||||||||
| 15 | IPInt | ||||||||||
| 16 | IPVersion | ||||||||||
| 17 | PrefixLength | ||||||||||
| 18 | NetWorksAddress | ||||||||||
| 19 | PackedBinary | ||||||||||
| 20 | Str | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | ## no critic (ValuesAndExpressions::ProhibitImplicitNewlines, NamingConventions::Capitalization) | ||||||||||
| 24 | { | ||||||||||
| 25 | 4 | my $t = quote_sub( | |||||||||
| 26 | q{ | ||||||||||
| 27 | ( defined $_[0] && !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) | ||||||||||
| 28 | or Net::Works::Types::_confess( | ||||||||||
| 29 | '%s is not a valid integer for an IP address', | ||||||||||
| 30 | $_[0] | ||||||||||
| 31 | ); | ||||||||||
| 32 | } | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 4 | ▶ | sub Int () { $t } | ||||||||
|
Subroutine
Int: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | { | ||||||||||
| 39 | 4 | my $t = quote_sub( | |||||||||
| 40 | q{ | ||||||||||
| 41 | ( | ||||||||||
| 42 | defined $_[0] && ( ( !ref $_[0] && $_[0] =~ /^[0-9]+\z/ ) | ||||||||||
| 43 | || ( Scalar::Util::blessed( $_[0] ) | ||||||||||
| 44 | && ( $_[0]->isa('Math::UInt128') || $_[0]->isa('Math::BigInt') ) ) | ||||||||||
| 45 | ) | ||||||||||
| 46 | ) | ||||||||||
| 47 | or Net::Works::Types::_confess( | ||||||||||
| 48 | '%s is not a valid integer for an IP address', | ||||||||||
| 49 | defined $_[0] ? $_[0] : 'undef' | ||||||||||
| 50 | ); | ||||||||||
| 51 | } | ||||||||||
| 52 | ); | ||||||||||
| 53 | |||||||||||
| 54 | 7 | ▶ | sub IPInt () { $t } | ||||||||
|
Subroutine
IPInt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | { | ||||||||||
| 58 | 4 | my $t = quote_sub( | |||||||||
| 59 | q{ | ||||||||||
| 60 | ( defined $_[0] && !ref $_[0] && ( $_[0] == 4 || $_[0] == 6 ) ) | ||||||||||
| 61 | or Net::Works::Types::_confess( | ||||||||||
| 62 | '%s is not a valid IP version (4 or 6)', | ||||||||||
| 63 | defined $_[0] ? $_[0] : 'undef' | ||||||||||
| 64 | ); | ||||||||||
| 65 | } | ||||||||||
| 66 | ); | ||||||||||
| 67 | |||||||||||
| 68 | 4 | ▶ | sub IPVersion () { $t } | ||||||||
|
Subroutine
IPVersion: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | { | ||||||||||
| 72 | 4 | my $t = quote_sub( | |||||||||
| 73 | q{ | ||||||||||
| 74 | ( !ref $_[0] && defined $_[0] && $_[0] =~ /^[0-9]+\z/ && $_[0] <= 128 ) | ||||||||||
| 75 | or Net::Works::Types::_confess( | ||||||||||
| 76 | '%s is not a valid IP network prefix length (0-128)', | ||||||||||
| 77 | defined $_[0] ? $_[0] : 'undef' | ||||||||||
| 78 | ); | ||||||||||
| 79 | } | ||||||||||
| 80 | ); | ||||||||||
| 81 | |||||||||||
| 82 | 3 | ▶ | sub PrefixLength () { $t } | ||||||||
|
Subroutine
PrefixLength: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | { | ||||||||||
| 86 | 4 | my $t = quote_sub( | |||||||||
| 87 | q{ | ||||||||||
| 88 | ( Scalar::Util::blessed( $_[0] ) && $_[0]->isa('Net::Works::Address') ) | ||||||||||
| 89 | or Net::Works::Types::_confess( | ||||||||||
| 90 | '%s is not a Net::Works::Address object', | ||||||||||
| 91 | $_[0] | ||||||||||
| 92 | ); | ||||||||||
| 93 | } | ||||||||||
| 94 | ); | ||||||||||
| 95 | |||||||||||
| 96 | 6 | ▶ | sub NetWorksAddress () { $t } | ||||||||
|
Subroutine
NetWorksAddress: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | { | ||||||||||
| 100 | 4 | my $t = quote_sub( | |||||||||
| 101 | q{ | ||||||||||
| 102 | ( defined $_[0] && !ref $_[0] ) | ||||||||||
| 103 | or Net::Works::Types::_confess( '%s is not binary data', $_[0] ); | ||||||||||
| 104 | } | ||||||||||
| 105 | ); | ||||||||||
| 106 | |||||||||||
| 107 | 4 | ▶ | sub PackedBinary () { $t } | ||||||||
|
Subroutine
PackedBinary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | { | ||||||||||
| 111 | 4 | my $t = quote_sub( | |||||||||
| 112 | q{ | ||||||||||
| 113 | ( defined $_[0] && !ref $_[0] ) | ||||||||||
| 114 | or Net::Works::Types::_confess( '%s is not a string', $_[0] ); | ||||||||||
| 115 | } | ||||||||||
| 116 | ); | ||||||||||
| 117 | |||||||||||
| 118 | 7 | ▶ | sub Str () { $t } | ||||||||
|
Subroutine
Str: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 119 | } | ||||||||||
| 120 | ## use critic | ||||||||||
| 121 | |||||||||||
| 122 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines, Variables::ProhibitPackageVars) | ||||||||||
| 123 | 4 | ▶ | sub _confess { | ||||||||
|
Subroutine
_confess: called CC=2 SCAR=7.1
| |||||||||||
| 124 | 32 | local $Carp::Internal{__PACKAGE__} = 1; | |||||||||
| 125 | |||||||||||
| 126 | 32 | ▶ | confess sprintf( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | $_[0], | ||||||||||
| 128 | defined $_[1] ? $_[1] : 'undef' | ||||||||||
| 129 | ); | ||||||||||
| 130 | } | ||||||||||
| 131 | ## use critic | ||||||||||
| 132 | |||||||||||
| 133 | 4 | 1; | |||||||||