File Coverage

blib/lib/Sah/Schema/net/ipv4.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Sah::Schema::net::ipv4;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-05-27'; # DATE
5             our $DIST = 'Sah-Schemas-Net'; # DIST
6             our $VERSION = '0.009'; # VERSION
7              
8 1     1   45660 use NetAddr::IP ();
  1         26466  
  1         67  
9              
10             our $schema = [obj => {
11             summary => 'IPv4 address',
12             isa => 'NetAddr::IP',
13             'x.perl.coerce_rules' => [
14             'From_str::net_ipv4',
15             ],
16              
17             examples => [
18             {value=>'', valid=>0},
19             #{value=>'12.34.56.78', valid=>1, validated_value=>NetAddr::IP->new("12.34.56.78")}, # commented for now, is_deeply() fails
20             {value=>'12.345.67.89', valid=>0},
21             ],
22              
23             }, {}];
24              
25             1;
26             # ABSTRACT: IPv4 address
27              
28             __END__
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             Sah::Schema::net::ipv4 - IPv4 address
37              
38             =head1 VERSION
39              
40             This document describes version 0.009 of Sah::Schema::net::ipv4 (from Perl distribution Sah-Schemas-Net), released on 2020-05-27.
41              
42             =head1 SYNOPSIS
43              
44             To check data against this schema (requires L<Data::Sah>):
45              
46             use Data::Sah qw(gen_validator);
47             my $validator = gen_validator("net::ipv4*");
48             say $validator->($data) ? "valid" : "INVALID!";
49              
50             # Data::Sah can also create validator that returns nice error message string
51             # and/or coerced value. Data::Sah can even create validator that targets other
52             # language, like JavaScript. All from the same schema. See its documentation
53             # for more details.
54              
55             To validate function parameters against this schema (requires L<Params::Sah>):
56              
57             use Params::Sah qw(gen_validator);
58              
59             sub myfunc {
60             my @args = @_;
61             state $validator = gen_validator("net::ipv4*");
62             $validator->(\@args);
63             ...
64             }
65              
66             To specify schema in L<Rinci> function metadata and use the metadata with
67             L<Perinci::CmdLine> to create a CLI:
68              
69             # in lib/MyApp.pm
70             package MyApp;
71             our %SPEC;
72             $SPEC{myfunc} = {
73             v => 1.1,
74             summary => 'Routine to do blah ...',
75             args => {
76             arg1 => {
77             summary => 'The blah blah argument',
78             schema => ['net::ipv4*'],
79             },
80             ...
81             },
82             };
83             sub myfunc {
84             my %args = @_;
85             ...
86             }
87             1;
88              
89             # in myapp.pl
90             package main;
91             use Perinci::CmdLine::Any;
92             Perinci::CmdLine::Any->new(url=>'MyApp::myfunc')->run;
93              
94             # in command-line
95             % ./myapp.pl --help
96             myapp - Routine to do blah ...
97             ...
98              
99             % ./myapp.pl --version
100              
101             % ./myapp.pl --arg1 ...
102              
103             Sample data:
104              
105             "" # INVALID
106              
107             "12.345.67.89" # INVALID
108              
109             =head1 DESCRIPTION
110              
111             Currently using L<NetAddr::IP> object.
112              
113             =head1 HOMEPAGE
114              
115             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Net>.
116              
117             =head1 SOURCE
118              
119             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Net>.
120              
121             =head1 BUGS
122              
123             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Net>
124              
125             When submitting a bug or request, please include a test-file or a
126             patch to an existing test-file that illustrates the bug or desired
127             feature.
128              
129             =head1 AUTHOR
130              
131             perlancar <perlancar@cpan.org>
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is copyright (c) 2020, 2019, 2018, 2016 by perlancar@cpan.org.
136              
137             This is free software; you can redistribute it and/or modify it under
138             the same terms as the Perl 5 programming language system itself.
139              
140             =cut