File Coverage

blib/lib/Specio/Constraint/Structured.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 37 38 97.3


line stmt bran cond sub pod time code
1             package Specio::Constraint::Structured;
2              
3 4     4   28 use strict;
  4         12  
  4         116  
4 4     4   20 use warnings;
  4         9  
  4         187  
5              
6             our $VERSION = '0.47';
7              
8 4     4   25 use List::Util qw( all );
  4         9  
  4         268  
9 4     4   29 use Role::Tiny::With;
  4         7  
  4         154  
10 4     4   22 use Specio::OO;
  4         10  
  4         207  
11 4     4   34 use Specio::TypeChecks qw( does_role );
  4         8  
  4         761  
12 4     4   37 use Storable qw( dclone );
  4         8  
  4         193  
13              
14 4     4   39 use Specio::Constraint::Role::Interface;
  4         12  
  4         656  
15             with 'Specio::Constraint::Role::Interface';
16              
17             {
18             ## no critic (Subroutines::ProtectPrivateSubs)
19             my $attrs = dclone( Specio::Constraint::Role::Interface::_attrs() );
20             ## use critic
21              
22             $attrs->{parent}{isa} = 'Specio::Constraint::Structurable';
23             $attrs->{parent}{required} = 1;
24              
25             $attrs->{parameters} = {
26             isa => 'HashRef',
27             required => 1,
28             };
29              
30             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
31             sub _attrs {
32 8     8   21 return $attrs;
33             }
34             }
35              
36             sub can_be_inlined {
37 40     40 0 267 my $self = shift;
38 40         97 return $self->_has_inline_generator;
39             }
40              
41             __PACKAGE__->_ooify;
42              
43             1;
44              
45             # ABSTRACT: A class which represents structured constraints
46              
47             __END__
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             Specio::Constraint::Structured - A class which represents structured constraints
56              
57             =head1 VERSION
58              
59             version 0.47
60              
61             =head1 SYNOPSIS
62              
63             my $tuple = t('Tuple');
64              
65             my $tuple_of_str_int = $tuple->parameterize( of => [ t('Str'), t('Int') ] );
66              
67             my $parent = $tuple_of_str_int->parent; # returns Tuple
68             my $parameters = $arrayref_of_int->parameters; # returns { of => [ t('Str'), t('Int') ] }
69              
70             =head1 DESCRIPTION
71              
72             This class implements the API for structured types.
73              
74             =for Pod::Coverage can_be_inlined type_parameter
75              
76             =head1 API
77              
78             This class implements the same API as L<Specio::Constraint::Simple>, with a few
79             additions.
80              
81             =head2 Specio::Constraint::Structured->new(...)
82              
83             This class's constructor accepts two additional parameters:
84              
85             =over 4
86              
87             =item * parent
88              
89             This should be the L<Specio::Constraint::Structurable> object from which this
90             object was created.
91              
92             This parameter is required.
93              
94             =item * parameters
95              
96             This is the hashref of parameters for the structured type. These are the
97             parameters returned by the C<Structurable> type's
98             C<parameterization_args_builder>. The exact form of this hashref will vary for
99             each structured type.
100              
101             This parameter is required.
102              
103             =back
104              
105             =head2 $type->parameters
106              
107             Returns the hashref that was passed to the constructor.
108              
109             =head1 SUPPORT
110              
111             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
112              
113             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
114              
115             =head1 SOURCE
116              
117             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
118              
119             =head1 AUTHOR
120              
121             Dave Rolsky <autarch@urth.org>
122              
123             =head1 COPYRIGHT AND LICENSE
124              
125             This software is Copyright (c) 2012 - 2021 by Dave Rolsky.
126              
127             This is free software, licensed under:
128              
129             The Artistic License 2.0 (GPL Compatible)
130              
131             The full text of the license can be found in the
132             F<LICENSE> file included with this distribution.
133              
134             =cut