File Coverage

blib/lib/MooseX/Types/LaxNum.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package MooseX::Types::LaxNum;
2              
3 1     1   16550 use strict;
  1         1  
  1         29  
4 1     1   3 use warnings;
  1         2  
  1         23  
5 1     1   578 use Moose::Util::TypeConstraints;
  1         186449  
  1         8  
6 1     1   1170 use Scalar::Util qw( looks_like_number );
  1         1  
  1         119  
7             # ABSTRACT: Old behaviour of the Num type
8              
9             my $value_type = Moose::Util::TypeConstraints::find_type_constraint('Value');
10             subtype 'LaxNum'
11             => as 'Str'
12             => where { Scalar::Util::looks_like_number($_) }
13             => inline_as {
14             # the long Str tests are redundant here
15             $value_type->_inline_check($_[1])
16             . ' && Scalar::Util::looks_like_number(' . $_[1] . ')'
17             };
18              
19             1;
20              
21             __END__
22              
23             =pod
24              
25             =head1 NAME
26              
27             MooseX::Types::LaxNum - Old behaviour of the Num type
28              
29             =head1 VERSION
30              
31             version 0.01
32              
33             =head1 SYNOPSIS
34              
35             #!/usr/bin/env perl
36              
37             use strict;
38             use warnings;
39              
40             package Foo {
41             use Moose;
42             use MooseX::Types::LaxNum;
43              
44             has 'laxnum', is => 'rw', isa => 'LaxNum';
45             }
46              
47             my $foo = Foo->new( laxnum => '1234' );
48              
49             =head1 DESCRIPTION
50              
51             C<LaxNum> accepts everything for which L<Scalar::Util/looks_like_number> return true.
52             It can be used to get the old behaviour of C<Moose::Util::TypeConstraints::Num>,
53             since Num has been changed to be more strict.
54              
55             =head1 NAME
56              
57             MooseX::Types::LaxNum
58              
59             =head1 AUTHOR
60              
61             Upasana Shuka, C<me@upasana.me>
62              
63             =head1 COPYRIGHT & LICENSE
64              
65             Copyright 2013 Upasana Shukla.
66              
67             This program is free software; you can redistribute it and/or modify
68             it under the same terms as Perl itself.
69              
70             =head1 AUTHOR
71              
72             Upasana Shukla <me@upasana.me>
73              
74             =head1 COPYRIGHT AND LICENSE
75              
76             This software is copyright (c) 2013 by Upasana Shukla.
77              
78             This is free software; you can redistribute it and/or modify it under
79             the same terms as the Perl 5 programming language system itself.
80              
81             =cut