line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::int; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
103157
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
401
|
use Catmandu::Util qw(is_string is_array_ref is_hash_ref); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
79
|
|
9
|
1
|
|
|
1
|
|
581
|
use Catmandu::Util::Path qw(as_path); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
53
|
|
10
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
718
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_fixer { |
18
|
14
|
|
|
14
|
|
116
|
my ($self) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
as_path($self->path)->updater( |
21
|
|
|
|
|
|
|
sub { |
22
|
13
|
|
|
13
|
|
24
|
my $val = $_[0]; |
23
|
13
|
100
|
66
|
|
|
87
|
if (is_string($val) and my ($num) = $val =~ /([+-]?[0-9]+)/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
24
|
6
|
|
|
|
|
118
|
$num + 0; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif (is_array_ref($val)) { |
27
|
3
|
|
|
|
|
54
|
scalar(@$val); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif (is_hash_ref($val)) { |
30
|
3
|
|
|
|
|
56
|
scalar(keys %$val); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
1
|
|
|
|
|
19
|
0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
14
|
|
|
|
|
50
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Catmandu::Fix::int - convert a value to an integer |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# year => "2016" |
52
|
|
|
|
|
|
|
int(year) |
53
|
|
|
|
|
|
|
# year => 2016 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# foo => "bar-123baz" |
56
|
|
|
|
|
|
|
int(foo) |
57
|
|
|
|
|
|
|
# foo => -123 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# foo => "" |
60
|
|
|
|
|
|
|
int(foo) |
61
|
|
|
|
|
|
|
# foo => 0 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# foo => "abc" |
64
|
|
|
|
|
|
|
int(foo) |
65
|
|
|
|
|
|
|
# foo => 0 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# foo => [] |
68
|
|
|
|
|
|
|
int(foo) |
69
|
|
|
|
|
|
|
# foo => 0 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# foo => ["a", "b", "c"] |
72
|
|
|
|
|
|
|
int(foo) |
73
|
|
|
|
|
|
|
# foo => 3 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# foo => {a => "b", c => "d"} |
76
|
|
|
|
|
|
|
int(foo) |
77
|
|
|
|
|
|
|
# foo => 2 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SEE ALSO |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
L<Catmandu::Fix> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |