| 1 | package Type::Tiny::Eq; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | our $VERSION = "0.03"; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use parent qw( Type::Tiny ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 12 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.8
Pod
documented
| |||||||||||||||||||||
| 12 | 12 | my $class = shift; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | _croak "Eq type constraints cannot have a parent constraint passed to the constructor" | ||||||||||||||||||||
| 17 | 12 | ▶ | if exists $opts{parent}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | _croak "Eq type constraints cannot have a constraint coderef passed to the constructor" | ||||||||||||||||||||
| 20 | 12 | ▶ | if exists $opts{constraint}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | _croak "Eq type constraints cannot have a inlining coderef passed to the constructor" | ||||||||||||||||||||
| 23 | 12 | ▶ | if exists $opts{inlined}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 12 | ▶ | _croak "Need to supply value" unless exists $opts{value}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 12 | ▶ | _croak "Eq value must be defined" unless defined $opts{value}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 10 | $opts{value} = "$opts{value}"; # stringify | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 10 | return $class->SUPER::new( %opts ); | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 30 | ▶ | sub value { $_[0]{value} } | ||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 10 | ▶ | sub _build_display_name { | ||||||||||||||||||
|
Subroutine
_build_display_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 10 | my $self = shift; | |||||||||||||||||||
| 38 | 10 | sprintf( "Eq['%s']", $self->value ); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 6 | ▶ | sub has_parent { | ||||||||||||||||||
|
Subroutine
has_parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 42 | 6 | !!0; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 10 | ▶ | sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint } | ||||||||||||||||||
|
Subroutine
constraint: called CC=2 SCAR=9.2
Pod
documented
Condition33%1/3
$_[0]{"constraint"} ||= $_[0]->_build_constraint
MC/DC0%0/2
$_[0]{"constraint"} ||= $_[0]->_build_constraint
$_[0]{"constraint"}
$_[0]->_build_constraint
Truth table33%1/3
A ||= B
A= $_[0]{"constraint"}B= $_[0]->_build_constraint
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 10 | ▶ | sub _build_constraint { | ||||||||||||||||||
|
Subroutine
_build_constraint: called CC=1 SCAR=2.0
| |||||||||||||||||||||
| 48 | 10 | my $self = shift; | |||||||||||||||||||
| 49 | 0 | ▶ | return sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 50 | 0 | ▶ | defined $_ && $_ eq $self->value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 10 | }; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 18 | ▶ | sub can_be_inlined { | ||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 55 | 18 | !!1; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 19 | ▶ | sub inline_check { | ||||||||||||||||||
|
Subroutine
inline_check: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 59 | 19 | my $self = shift; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 19 | my $value = $self->value; | |||||||||||||||||||
| 62 | 19 | my $code = "(defined($_[0]) && $_[0] eq '$value')"; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 19 | ▶ | return "do { $Type::Tiny::SafePackage $code }" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | if $Type::Tiny::AvoidCallbacks; ## no critic (Variables::ProhibitPackageVars) | ||||||||||||||||||||
| 66 | 19 | return $code; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 2 | 1; | |||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||