line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Clean::ToNonStringyNumber; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-09-01'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.050'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
98779
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
408
|
use parent qw(Data::Clean); |
|
1
|
|
|
|
|
245
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
5722
|
use vars qw($creating_singleton); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
192
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub command_replace_with_non_stringy_number { |
14
|
1
|
|
|
1
|
0
|
439
|
require Scalar::Util::LooksLikeNumber; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
369
|
my ($self, $args) = @_; |
17
|
1
|
|
|
|
|
4
|
return '{{var}} = Scalar::Util::LooksLikeNumber::looks_like_number({{var}}) =~ /\\A(?:1|5|9|13)\\z/ ? {{var}}+0 : {{var}}'; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
1
|
|
|
1
|
1
|
3
|
my ($class, %opts) = @_; |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
33
|
|
|
7
|
if (!%opts && !$creating_singleton) { |
24
|
0
|
|
|
|
|
0
|
warn "You are creating a new ".__PACKAGE__." object without customizing options. ". |
25
|
|
|
|
|
|
|
"You probably want to call get_cleanser() yet to get a singleton instead?"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
50
|
|
|
6
|
$opts{""} //= ['replace_with_non_stringy_number']; |
29
|
1
|
|
|
|
|
9
|
$class->SUPER::new(%opts); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_cleanser { |
33
|
1
|
|
|
1
|
1
|
107
|
my $class = shift; |
34
|
1
|
|
|
|
|
2
|
local $creating_singleton = 1; |
35
|
1
|
|
|
|
|
4
|
state $singleton = $class->new; |
36
|
1
|
|
|
|
|
1671
|
$singleton; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
# ABSTRACT: Convert stringy numbers in data to non-stringy numbers |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding UTF-8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Data::Clean::ToNonStringyNumber - Convert stringy numbers in data to non-stringy numbers |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 VERSION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This document describes version 0.050 of Data::Clean::ToNonStringyNumber (from Perl distribution Data-Clean-ToStringyNumber), released on 2019-09-01. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use Data::Clean::ToNonStringyNumber; |
59
|
|
|
|
|
|
|
my $cleanser = Data::Clean::ToNonStringyNumber->get_cleanser; |
60
|
|
|
|
|
|
|
my $data = ["a", 1, "1.2", []]; |
61
|
|
|
|
|
|
|
my $cleaned = $cleanser->clean_in_place($data); # -> ["a", 1, 1.2, []] |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This class can convert stringy numbers in your data to non-stringy ones. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=for Pod::Coverage ^(new|command_.+)$ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 METHODS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 CLASS->get_cleanser => $obj |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Return a singleton instance. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 $obj->clean_in_place($data) => $cleaned |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Clean $data. Modify data in-place. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 $obj->clone_and_clean($data) => $cleaned |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Clean $data. Clone $data first. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 HOMEPAGE |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Data-Clean-ToStringyNumber>. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SOURCE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Data-Clean-ToStringyNumber>. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 BUGS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Clean-ToStringyNumber> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
96
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
97
|
|
|
|
|
|
|
feature. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SEE ALSO |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Data::Clean::ToStringyNumber> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2016, 2014, 2013 by perlancar@cpan.org. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
112
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |