File Coverage

lib/Type/Tiny/_DeclaredType.pm
Criterion Covered Total %
statement 29 30 96.6
branch 5 10 50.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 44 50 88.0


line stmt bran cond sub pod time code
1             package Type::Tiny::_DeclaredType;
2              
3 57     57   1219 use 5.008001;
  57         230  
4 57     57   329 use strict;
  57         116  
  57         3103  
5 57     57   1210 use warnings;
  57         338  
  57         5469  
6              
7             BEGIN {
8 57     57   220 $Type::Tiny::_DeclaredType::AUTHORITY = 'cpan:TOBYINK';
9 57         2901 $Type::Tiny::_DeclaredType::VERSION = '2.010001';
10             }
11              
12             $Type::Tiny::_DeclaredType::VERSION =~ tr/_//d;
13              
14 57     57   369 use Type::Tiny ();
  57         122  
  57         20385  
15             our @ISA = qw( Type::Tiny );
16              
17             sub new {
18 577     577 1 1100 my $class = shift;
19 577 50       5559 my %opts = @_ == 1 ? %{ +shift } : @_;
  0         0  
20            
21 577         1466 my $library = delete $opts{library};
22 577         1221 my $name = delete $opts{name};
23            
24 577 50       2947 $library->can( 'get_type' )
25             or Type::Tiny::_croak( "Expected $library to be a type library, but it doesn't seem to be" );
26            
27 577         1451 $opts{display_name} = $name;
28             $opts{constraint} = sub {
29 2 50   2   9 my $val = @_ ? pop : $_;
30 2         19 $library->get_type( $name )->check( $val );
31 577         3575 };
32             $opts{inlined} = sub {
33 135 50   135   243 my $val = @_ ? pop : $_;
34 135         295 sprintf( '%s::is_%s(%s)', $library, $name, $val );
35 577         2084 };
36             $opts{_build_coercion} = sub {
37 7     7   47 my $realtype = $library->get_type( $name );
38 7 50       18 $_[0] = $realtype->coercion if $realtype;
39 577         1918 };
40 577         3125 $class->SUPER::new( %opts );
41             } #/ sub new
42              
43             1;
44              
45             __END__