| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Specio::Constraint::Parameterized; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 28 |  |  | 28 |  | 190 | use strict; | 
|  | 28 |  |  |  |  | 54 |  | 
|  | 28 |  |  |  |  | 749 |  | 
| 4 | 28 |  |  | 28 |  | 137 | use warnings; | 
|  | 28 |  |  |  |  | 46 |  | 
|  | 28 |  |  |  |  | 986 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '0.46'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 28 |  |  | 28 |  | 138 | use Role::Tiny::With; | 
|  | 28 |  |  |  |  | 47 |  | 
|  | 28 |  |  |  |  | 1015 |  | 
| 9 | 28 |  |  | 28 |  | 6178 | use Specio::OO; | 
|  | 28 |  |  |  |  | 62 |  | 
|  | 28 |  |  |  |  | 1371 |  | 
| 10 | 28 |  |  | 28 |  | 164 | use Storable qw( dclone ); | 
|  | 28 |  |  |  |  | 84 |  | 
|  | 28 |  |  |  |  | 986 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 28 |  |  | 28 |  | 7216 | use Specio::Constraint::Role::Interface; | 
|  | 28 |  |  |  |  | 59 |  | 
|  | 28 |  |  |  |  | 7211 |  | 
| 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 | 56 |  |  | 56 |  | 110 | return $attrs; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub _has_name { | 
| 39 | 11 |  |  | 11 |  | 25 | my $self = shift; | 
| 40 | 11 |  |  |  |  | 44 | return defined $self->name; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub _build_name { | 
| 44 | 10 |  |  | 10 |  | 63 | my $self = shift; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | ## no critic (Subroutines::ProtectPrivateSubs) | 
| 47 | 10 | 50 | 33 |  |  | 39 | return unless $self->parent->_has_name && $self->parameter->_has_name; | 
| 48 | 10 |  |  |  |  | 220 | return $self->parent->name . '[' . $self->parameter->name . ']'; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub can_be_inlined { | 
| 52 | 33 |  |  | 33 | 0 | 81 | my $self = shift; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 33 |  | 33 |  |  | 91 | 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.46 | 
| 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 this | 
| 114 |  |  |  |  |  |  | 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 - 2020 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 |