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 44     44   1198 use 5.008001;
  44         174  
4 44     44   281 use strict;
  44         92  
  44         999  
5 44     44   220 use warnings;
  44         98  
  44         2010  
6              
7             BEGIN {
8 44     44   164 $Type::Tiny::_DeclaredType::AUTHORITY = 'cpan:TOBYINK';
9 44         1387 $Type::Tiny::_DeclaredType::VERSION = '2.004000';
10             }
11              
12             $Type::Tiny::_DeclaredType::VERSION =~ tr/_//d;
13              
14 44     44   257 use Type::Tiny ();
  44         94  
  44         10938  
15             our @ISA = qw( Type::Tiny );
16              
17             sub new {
18 421     421 1 829 my $class = shift;
19 421 50       1688 my %opts = @_ == 1 ? %{ +shift } : @_;
  0         0  
20            
21 421         1011 my $library = delete $opts{library};
22 421         904 my $name = delete $opts{name};
23            
24 421 50       1903 $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 421         923 $opts{display_name} = $name;
28             $opts{constraint} = sub {
29 2 50   2   9 my $val = @_ ? pop : $_;
30 2         15 $library->get_type( $name )->check( $val );
31 421         4110 };
32             $opts{inlined} = sub {
33 135 50   135   265 my $val = @_ ? pop : $_;
34 135         444 sprintf( '%s::is_%s(%s)', $library, $name, $val );
35 421         1358 };
36             $opts{_build_coercion} = sub {
37 7     7   31 my $realtype = $library->get_type( $name );
38 7 50       22 $_[0] = $realtype->coercion if $realtype;
39 421         1257 };
40 421         2039 $class->SUPER::new( %opts );
41             } #/ sub new
42              
43             1;
44              
45             __END__