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   25 use strict;
  4         9  
  4         207  
4 4     4   19 use warnings;
  4         5  
  4         296  
5              
6             our $VERSION = '0.53';
7              
8 4     4   27 use List::Util 1.33 qw( all );
  4         104  
  4         283  
9 4     4   22 use Role::Tiny::With;
  4         13  
  4         201  
10 4     4   23 use Specio qw( _clone );
  4         7  
  4         179  
11 4     4   22 use Specio::OO;
  4         10  
  4         265  
12 4     4   36 use Specio::TypeChecks qw( does_role );
  4         8  
  4         225  
13              
14 4     4   22 use Specio::Constraint::Role::Interface;
  4         31  
  4         829  
15             with 'Specio::Constraint::Role::Interface';
16              
17             {
18             ## no critic (Subroutines::ProtectPrivateSubs)
19             my $attrs = _clone( 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 11     11   31 return $attrs;
33             }
34             }
35              
36             sub can_be_inlined {
37 40     40 0 312 my $self = shift;
38 40         119 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.53
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             =head1 SOURCE
114              
115             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
116              
117             =head1 AUTHOR
118              
119             Dave Rolsky <autarch@urth.org>
120              
121             =head1 COPYRIGHT AND LICENSE
122              
123             This software is Copyright (c) 2012 - 2025 by Dave Rolsky.
124              
125             This is free software, licensed under:
126              
127             The Artistic License 2.0 (GPL Compatible)
128              
129             The full text of the license can be found in the
130             F<LICENSE> file included with this distribution.
131              
132             =cut