File Coverage

blib/lib/Poz/Types/is.pm
Criterion Covered Total %
statement 19 19 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Poz::Types::is;
2 11     11   69 use parent 'Poz::Types::scalar';
  11         24  
  11         105  
3 11     11   1096 use 5.032;
  11         38  
4 11     11   54 use strict;
  11         27  
  11         350  
5 11     11   54 use warnings;
  11         29  
  11         2479  
6              
7             sub new {
8 6     6 1 16 my ($class, $is) = @_;
9 6         32 my $opts = {
10             is => $is,
11             required_error => 'required',
12             invalid_type_error => 'Not a ' . $is,
13             };
14 6         39 my $self = $class->SUPER::new($opts);
15 6         47 return $self;
16             }
17              
18             sub rule {
19 12     12 1 25 my ($self, $value) = @_;
20 12 50       31 return $self->{required_error} unless defined $value;
21 12 100       88 return $self->{invalid_type_error} unless $value->isa($self->{is});
22 8         24 return;
23             }
24              
25             1;
26              
27             =head1 NAME
28              
29             Poz::Types::is - Type handling for Poz framework
30              
31             =head1 SYNOPSIS
32              
33             use Poz qw/z/;
34              
35             my $is_type = z->is('Some::Class');
36             my $obj = bless {}, 'Some::Class';
37             my $other_obj = bless {}, 'Some::Other::Class';
38             $is_type->parse($obj); # returns $obj
39             $is_type->parse($other_obj); # throws exception
40              
41             =head1 DESCRIPTION
42              
43             Poz::Types::is provides methods to handle types based on their class within the Poz. It allows setting default values, marking values as nullable or optional, and coercing values.
44              
45             =head2 METHODS
46              
47             =over 4
48              
49             =item new
50              
51             Creates a new instance of Poz::Types::is.
52              
53             =item rule
54              
55             Validates the value against the type.
56              
57             =back
58              
59             =head1 SEE ALSO
60              
61             L<Poz::Types>, L<Poz::Types::scalar>
62              
63             =head1 AUTHOR
64              
65             ytnobody E<lt>ytnobody@gmail.comE<gt>
66              
67             =cut