| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Sah::Coerce::perl::To_obj::From_str::net_ipv4; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# AUTHOR |
|
4
|
|
|
|
|
|
|
our $DATE = '2020-05-27'; # DATE |
|
5
|
|
|
|
|
|
|
our $DIST = 'Sah-Schemas-Net'; # DIST |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
22917
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
180
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub meta { |
|
13
|
|
|
|
|
|
|
+{ |
|
14
|
1
|
|
|
1
|
0
|
13
|
v => 4, |
|
15
|
|
|
|
|
|
|
summary => 'Coerce IPv4 address object from string', |
|
16
|
|
|
|
|
|
|
might_fail => 1, |
|
17
|
|
|
|
|
|
|
prio => 50, |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub coerce { |
|
22
|
1
|
|
|
1
|
0
|
15
|
my %args = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
my $dt = $args{data_term}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
2
|
my $res = {}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
50
|
|
|
7
|
$res->{modules}{'NetAddr::IP'} //= 0; |
|
29
|
1
|
|
|
|
|
3
|
$res->{expr_match} = "!ref($dt)"; |
|
30
|
1
|
|
|
|
|
4
|
$res->{expr_coerce} = join( |
|
31
|
|
|
|
|
|
|
"", |
|
32
|
|
|
|
|
|
|
"do { my \$ip = NetAddr::IP->new($dt); if (!\$ip) { ['Invalid IP address syntax'] } ", |
|
33
|
|
|
|
|
|
|
"elsif (\$ip->bits != 32) { ['Not an IPv4 address (probably IPv6)'] } ", |
|
34
|
|
|
|
|
|
|
"elsif (\$ip->masklen != 32) { ['Not a single IPv4 address (an IP range)'] } ", |
|
35
|
|
|
|
|
|
|
"else { [undef, \$ip] } ", |
|
36
|
|
|
|
|
|
|
"}", |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
$res; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
|
43
|
|
|
|
|
|
|
# ABSTRACT: Coerce IPv4 address object from string |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Data::Sah::Coerce::perl::To_obj::From_str::net_ipv4 - Coerce IPv4 address object from string |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This document describes version 0.009 of Data::Sah::Coerce::perl::To_obj::From_str::net_ipv4 (from Perl distribution Sah-Schemas-Net), released on 2020-05-27. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
To use in a Sah schema: |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
["obj",{"x.perl.coerce_rules"=>["From_str::net_ipv4"]}] |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=for Pod::Coverage ^(meta|coerce)$ |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 HOMEPAGE |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Net>. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SOURCE |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Net>. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 BUGS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Net> |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
80
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
81
|
|
|
|
|
|
|
feature. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This software is copyright (c) 2020, 2019, 2018, 2016 by perlancar@cpan.org. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
92
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |