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 46     46   1275 use 5.008001;
  46         208  
4 46     46   305 use strict;
  46         102  
  46         1153  
5 46     46   259 use warnings;
  46         120  
  46         2242  
6              
7             BEGIN {
8 46     46   543 $Type::Tiny::_DeclaredType::AUTHORITY = 'cpan:TOBYINK';
9 46         1519 $Type::Tiny::_DeclaredType::VERSION = '2.003_000';
10             }
11              
12             $Type::Tiny::_DeclaredType::VERSION =~ tr/_//d;
13              
14 46     46   298 use Type::Tiny ();
  46         117  
  46         11741  
15             our @ISA = qw( Type::Tiny );
16              
17             sub new {
18 423     423 1 818 my $class = shift;
19 423 50       1802 my %opts = @_ == 1 ? %{ +shift } : @_;
  0         0  
20            
21 423         1009 my $library = delete $opts{library};
22 423         858 my $name = delete $opts{name};
23            
24 423 50       1921 $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 423         909 $opts{display_name} = $name;
28             $opts{constraint} = sub {
29 2 50   2   9 my $val = @_ ? pop : $_;
30 2         13 $library->get_type( $name )->check( $val );
31 423         1948 };
32             $opts{inlined} = sub {
33 135 50   135   265 my $val = @_ ? pop : $_;
34 135         490 sprintf( '%s::is_%s(%s)', $library, $name, $val );
35 423         1314 };
36             $opts{_build_coercion} = sub {
37 7     7   35 my $realtype = $library->get_type( $name );
38 7 50       22 $_[0] = $realtype->coercion if $realtype;
39 423         1187 };
40 423         2032 $class->SUPER::new( %opts );
41             } #/ sub new
42              
43             1;
44              
45             __END__
46              
47             =pod
48              
49             =encoding utf-8
50              
51             =head1 NAME
52              
53             Type::Tiny::_DeclaredType - half-defined type constraint
54              
55             =head1 STATUS
56              
57             This module is considered part of Type-Tiny's internals. It is not
58             covered by the
59             L<Type-Tiny stability policy|Type::Tiny::Manual::Policies/"STABILITY">.
60              
61             =head1 DESCRIPTION
62              
63             This is not considered part of Type::Tiny's public API.
64              
65             It is a class representing a declared-but-not-defined type constraint.
66             It inherits from L<Type::Tiny>.
67              
68             =head2 Constructor
69              
70             =over
71              
72             =item C<< new(%options) >>
73              
74             =back
75              
76             =head1 BUGS
77              
78             Please report any bugs to
79             L<https://github.com/tobyink/p5-type-tiny/issues>.
80              
81             =head1 AUTHOR
82              
83             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
84              
85             =head1 COPYRIGHT AND LICENCE
86              
87             This software is copyright (c) 2013-2023 by Toby Inkster.
88              
89             This is free software; you can redistribute it and/or modify it under
90             the same terms as the Perl 5 programming language system itself.
91              
92             =head1 DISCLAIMER OF WARRANTIES
93              
94             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
95             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
96             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.