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 41     41   1175 use 5.008001;
  41         150  
4 41     41   271 use strict;
  41         238  
  41         1050  
5 41     41   229 use warnings;
  41         269  
  41         2028  
6              
7             BEGIN {
8 41     41   192 $Type::Tiny::_DeclaredType::AUTHORITY = 'cpan:TOBYINK';
9 41         1353 $Type::Tiny::_DeclaredType::VERSION = '2.002001';
10             }
11              
12             $Type::Tiny::_DeclaredType::VERSION =~ tr/_//d;
13              
14 41     41   273 use Type::Tiny ();
  41         92  
  41         10619  
15             our @ISA = qw( Type::Tiny );
16              
17             sub new {
18 385     385 1 751 my $class = shift;
19 385 50       1620 my %opts = @_ == 1 ? %{ +shift } : @_;
  0         0  
20            
21 385         1258 my $library = delete $opts{library};
22 385         769 my $name = delete $opts{name};
23            
24 385 50       1894 $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 385         875 $opts{display_name} = $name;
28             $opts{constraint} = sub {
29 2 50   2   8 my $val = @_ ? pop : $_;
30 2         13 $library->get_type( $name )->check( $val );
31 385         1818 };
32             $opts{inlined} = sub {
33 55 50   55   131 my $val = @_ ? pop : $_;
34 55         234 sprintf( '%s::is_%s(%s)', $library, $name, $val );
35 385         1219 };
36             $opts{_build_coercion} = sub {
37 7     7   37 my $realtype = $library->get_type( $name );
38 7 50       56 $_[0] = $realtype->coercion if $realtype;
39 385         1108 };
40 385         1869 $class->SUPER::new( %opts );
41             } #/ sub new
42              
43             1;
44              
45             __END__