Poz/Types/null.pm

filter: Statementstmt 54.5% 12 / 22 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 41.8% 18 / 43 CC 6 SCAR 23.9
CC
6
Cov
38%
new
20.0
rule
12.0
BEGIN
1.0
CRAP 10.9
« Poz/Types/union.pm ↑ Summary Poz/Types/enum.pm »
1 package Poz::Types::null;
2 11 ▶use 5.032;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use parent 'Poz::Types::scalar';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
8 0 my ($class, $opts) = @_;
9 0 ▶ $opts = $opts || {};
Condition0%0/2
$opts || {}
l!l
00
MC/DC0%0/1
$opts || {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
10 0 ▶ $opts->{required_error} //= "Not a null";
Condition0%0/2
$opts->{"required_error"} //= "Not a null"
l!l
00
MC/DC0%0/1
$opts->{"required_error"} //= "Not a null"
$opts->{"required_error"}
Truth table0%0/2
A
A= $opts->{"required_error"}
Aresult
11
00
11 0 ▶ $opts->{invalid_type_error} //= "Not a null";
Condition0%0/2
$opts->{"invalid_type_error"} //= "Not a null"
l!l
00
MC/DC0%0/1
$opts->{"invalid_type_error"} //= "Not a null"
$opts->{"invalid_type_error"}
Truth table0%0/2
A
A= $opts->{"invalid_type_error"}
Aresult
11
00
12 0 my $self = $class->SUPER::new($opts);
13 0 return $self;
14 }
15  
16 0 ▶sub rule {
Subroutine rule: not called CC=3 SCAR=24.8
Pod documented
17 0 my ($self, $value) = @_;
18 0 ▶ return $self->{required_error} if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
19 0 ▶ return $self->{invalid_type_error} if $value ;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
20 0 return;
21 };
22  
23 11 1;
24  
25 =head1 NAME
26  
27 Poz::Types::null - Null type validation for Poz::Types
28  
29 =head1 SYNOPSIS
30  
31 use Poz qw/z/;
32  
33 my $null_validator = z->null;
34  
35 $null_validator->parse(undef); # returns undef
36 $null_validator->parse(1); # returns error message
37  
38 my $array_with_null_or_number = z->array(z->union(z->null, z->number));
39 $array_with_null_or_number->parse([undef, 1]); # returns [undef, 1]
40 $array_with_null_or_number->parse([1, 2]); # returns [1, 2]
41 $array_with_null_or_number->parse([undef, "a"]); # returns error message
42  
43 =head1 DESCRIPTION
44  
45 This module provides a null type validator for Poz::Types. It can be used to validate that a value is C<undef>.
46  
47 =head1 METHODS
48  
49 =head2 rule
50  
51 my $error = $null_validator->rule($value);
52  
53 Validates the given value. Returns an error message if the value is not C<undef>, otherwise returns C<undef>.
54  
55 =head1 LICENSE
56  
57 Copyright (C) ytnobody.
58  
59 This library is free software; you can redistribute it and/or modify
60 it under the same terms as Perl itself.
61  
62 =head1 AUTHOR
63  
64 ytnobody E<lt>ytnobody@gmail.comE<gt>
65  
66 =cut
« Poz/Types/union.pm ↑ Summary Poz/Types/enum.pm »