| 1 | package Params::Validate::Checks::Net; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Params::Validate::Checks::Net - Params::Validate checks for functions taking | ||
| 6 | network-related arguments | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use Params::Validate::Checks qw<validate as>; | ||
| 11 | use Params::Validate::Checks::Net; | ||
| 12 | |||
| 13 | sub configure_website | ||
| 14 | { | ||
| 15 | my %arg = validate @_, | ||
| 16 | { | ||
| 17 | website => {as 'domain'}, | ||
| 18 | nameserver => {as 'domain'}, | ||
| 19 | ip_address => {as 'public_ip_address'}, | ||
| 20 | }; | ||
| 21 | |||
| 22 | # Do something with $arg{website}, $arg{nameserver}, $arg{ip_address} ... | ||
| 23 | } | ||
| 24 | |||
| 25 | sub check_network | ||
| 26 | { | ||
| 27 | my %arg = validate @_. | ||
| 28 | { | ||
| 29 | device => {as 'hostname'}, | ||
| 30 | mac_address => {as 'mac_address'}, | ||
| 31 | timeout => {as 'pos_int', default => 10}, | ||
| 32 | }; | ||
| 33 | |||
| 34 | # Do something with $arg{device}, $arg{mac_address}, $arg{timeout} ... | ||
| 35 | } | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | |||
| 40 | 5 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 41 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 42 | |||
| 43 | 5 | ▶ | use Params::Validate::Checks; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | |||
| 45 | 5 | ▶ | use Data::Validate::Domain 0.02 qw<is_domain is_hostname>; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | 5 | ▶ | use Data::Validate::IP qw<is_ipv4 is_public_ipv4>; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 5 | ▶ | use Regexp::Common qw<net>; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | |||
| 50 | 5 | our $VERSION = 0.01; | |
| 51 | |||
| 52 | |||
| 53 | =head1 DESCRIPTION | ||
| 54 | |||
| 55 | This is a library of named checks for use with L<Params::Validate> to validate | ||
| 56 | function and method arguments that should be networky things: domain names, | ||
| 57 | hostnames, IP addresses, or mac addresses. See L<Params::Validate::Checks> for | ||
| 58 | details of the overall system. | ||
| 59 | |||
| 60 | =head2 Checks | ||
| 61 | |||
| 62 | The following named checks are supplied by this module. In all cases only the | ||
| 63 | syntax is checked, not that the entity in question actually exists on the | ||
| 64 | network: | ||
| 65 | |||
| 66 | =over | ||
| 67 | |||
| 68 | =item C<domain> | ||
| 69 | |||
| 70 | an internet domain name, such as "123-reg.co.uk"; it must having a known | ||
| 71 | top-level domain (such as ".uk") | ||
| 72 | |||
| 73 | =item C<hostname> | ||
| 74 | |||
| 75 | an internet hostname; this includes all domain names but also unqualified | ||
| 76 | hostnames like "www1", which may be valid on internal networks | ||
| 77 | |||
| 78 | =item C<ip_address> | ||
| 79 | |||
| 80 | an IP address (version 4), such as "212.100.234.56" | ||
| 81 | |||
| 82 | =item C<public_ip_address> | ||
| 83 | |||
| 84 | like C<ip_address>, but excluding addresses such as "192.168.0.42" which are | ||
| 85 | internal-only, not publicly reachable over the internet | ||
| 86 | |||
| 87 | =item C<mac_address> | ||
| 88 | |||
| 89 | the mac address of a network device, such as "00:0E:35:17:F3:4E" | ||
| 90 | |||
| 91 | =back | ||
| 92 | |||
| 93 | Feedback is welcome on further checks that should be added. | ||
| 94 | |||
| 95 | =cut | ||
| 96 | |||
| 97 | |||
| 98 | 5 | Params::Validate::Checks::register | |
| 99 | domain => \&is_domain, | ||
| 100 | hostname => \&is_hostname, | ||
| 101 | ip_address => \&is_ipv4, | ||
| 102 | public_ip_address => \&is_public_ipv4, | ||
| 103 | mac_address => qr/^$RE{net}{MAC}\z/, | ||
| 104 | ; | ||
| 105 | |||
| 106 | |||
| 107 | =head1 SEE ALSO | ||
| 108 | |||
| 109 | =over 2 | ||
| 110 | |||
| 111 | =item * | ||
| 112 | |||
| 113 | L<Params::Validate::Checks>, the framework this is using | ||
| 114 | |||
| 115 | =item * | ||
| 116 | |||
| 117 | L<Data::Validate::Domain>, provider of the domain name and hostname checks | ||
| 118 | |||
| 119 | =item * | ||
| 120 | |||
| 121 | L<Data::Validate::IP>, provider of the IP address checks | ||
| 122 | |||
| 123 | =item * | ||
| 124 | |||
| 125 | L<Regexp::Common>, provider of the mac address check | ||
| 126 | |||
| 127 | =back | ||
| 128 | |||
| 129 | =head1 CREDITS | ||
| 130 | |||
| 131 | Written and maintained by Smylers <smylers@cpan.org> | ||
| 132 | |||
| 133 | Thanks to the authors and maintainers of the above modules that are doing the | ||
| 134 | actual syntax checks. | ||
| 135 | |||
| 136 | =head1 COPYRIGHT & LICENCE | ||
| 137 | |||
| 138 | Copyright 2006-2008 by Smylers. | ||
| 139 | |||
| 140 | This library is software libre; you may redistribute it and modify it under the | ||
| 141 | terms of any of these licences: | ||
| 142 | |||
| 143 | =over 2 | ||
| 144 | |||
| 145 | =item * | ||
| 146 | |||
| 147 | L<The GNU General Public License, version 2|perlgpl> | ||
| 148 | |||
| 149 | =item * | ||
| 150 | |||
| 151 | The GNU General Public License, version 3 | ||
| 152 | |||
| 153 | =item * | ||
| 154 | |||
| 155 | L<The Artistic License|perlartistic> | ||
| 156 | |||
| 157 | =item * | ||
| 158 | |||
| 159 | The Artistic License 2.0 | ||
| 160 | |||
| 161 | =back | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | |||
| 166 | 5 | 1; | |