File Coverage

blib/lib/Specio/Constraint/Parameterized.pm
Criterion Covered Total %
statement 26 27 96.3
branch 1 2 50.0
condition 2 6 33.3
subroutine 10 11 90.9
pod 0 2 0.0
total 39 48 81.2


line stmt bran cond sub pod time code
1             package Specio::Constraint::Parameterized;
2              
3 29     29   206 use strict;
  29         56  
  29         870  
4 29     29   204 use warnings;
  29         58  
  29         1155  
5              
6             our $VERSION = '0.47';
7              
8 29     29   159 use Role::Tiny::With;
  29         55  
  29         1254  
9 29     29   7582 use Specio::OO;
  29         75  
  29         1612  
10 29     29   184 use Storable qw( dclone );
  29         56  
  29         1274  
11              
12 29     29   8574 use Specio::Constraint::Role::Interface;
  29         68  
  29         8918  
13             with 'Specio::Constraint::Role::Interface';
14              
15             {
16             ## no critic (Subroutines::ProtectPrivateSubs)
17             my $attrs = dclone( Specio::Constraint::Role::Interface::_attrs() );
18             ## use critic
19              
20             $attrs->{parent}{isa} = 'Specio::Constraint::Parameterizable';
21             $attrs->{parent}{required} = 1;
22              
23             delete $attrs->{name}{predicate};
24             $attrs->{name}{lazy} = 1;
25             $attrs->{name}{builder} = '_build_name';
26              
27             $attrs->{parameter} = {
28             does => 'Specio::Constraint::Role::Interface',
29             required => 1,
30             };
31              
32             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
33             sub _attrs {
34 58     58   134 return $attrs;
35             }
36             }
37              
38             sub _has_name {
39 23     23   49 my $self = shift;
40 23         80 return defined $self->name;
41             }
42              
43             sub _build_name {
44 14     14   91 my $self = shift;
45              
46             ## no critic (Subroutines::ProtectPrivateSubs)
47 14 50 33     59 return unless $self->parent->_has_name && $self->parameter->_has_name;
48 14         306 return $self->parent->name . '[' . $self->parameter->name . ']';
49             }
50              
51             sub can_be_inlined {
52 33     33 0 80 my $self = shift;
53              
54 33   33     92 return $self->_has_inline_generator
55             && $self->parameter->can_be_inlined;
56             }
57              
58             # Moose compatibility methods - these exist as a temporary hack to make Specio
59             # work with Moose.
60              
61             sub type_parameter {
62 0     0 0   shift->parameter;
63             }
64              
65             __PACKAGE__->_ooify;
66              
67             1;
68              
69             # ABSTRACT: A class which represents parameterized constraints
70              
71             __END__
72              
73             =pod
74              
75             =encoding UTF-8
76              
77             =head1 NAME
78              
79             Specio::Constraint::Parameterized - A class which represents parameterized constraints
80              
81             =head1 VERSION
82              
83             version 0.47
84              
85             =head1 SYNOPSIS
86              
87             my $arrayref = t('ArrayRef');
88              
89             my $arrayref_of_int = $arrayref->parameterize( of => t('Int') );
90              
91             my $parent = $arrayref_of_int->parent; # returns ArrayRef
92             my $parameter = $arrayref_of_int->parameter; # returns Int
93              
94             =head1 DESCRIPTION
95              
96             This class implements the API for parameterized types.
97              
98             =for Pod::Coverage can_be_inlined type_parameter
99              
100             =head1 API
101              
102             This class implements the same API as L<Specio::Constraint::Simple>, with a few
103             additions.
104              
105             =head2 Specio::Constraint::Parameterized->new(...)
106              
107             This class's constructor accepts two additional parameters:
108              
109             =over 4
110              
111             =item * parent
112              
113             This should be the L<Specio::Constraint::Parameterizable> object from which
114             this object was created.
115              
116             This parameter is required.
117              
118             =item * parameter
119              
120             This is the type parameter for the parameterized type. This must be an object
121             which does the L<Specio::Constraint::Role::Interface> role.
122              
123             This parameter is required.
124              
125             =back
126              
127             =head2 $type->parameter
128              
129             Returns the type that was passed to the constructor.
130              
131             =head1 SUPPORT
132              
133             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
134              
135             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
136              
137             =head1 SOURCE
138              
139             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
140              
141             =head1 AUTHOR
142              
143             Dave Rolsky <autarch@urth.org>
144              
145             =head1 COPYRIGHT AND LICENSE
146              
147             This software is Copyright (c) 2012 - 2021 by Dave Rolsky.
148              
149             This is free software, licensed under:
150              
151             The Artistic License 2.0 (GPL Compatible)
152              
153             The full text of the license can be found in the
154             F<LICENSE> file included with this distribution.
155              
156             =cut