-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from ssm/feature/more-robust-async
Feature/more robust async
- Loading branch information
Showing
6 changed files
with
210 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package Munin::Common::Utils; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Exporter (); | ||
our @ISA = qw/Exporter/; | ||
our @EXPORT_OK = qw( is_valid_hostname ); | ||
|
||
use Params::Validate qw( :all ); | ||
use List::Util qw( all any ); | ||
|
||
### Set operations ############################################################# | ||
|
||
sub is_valid_hostname { | ||
my ($hostname) = validate_pos(@_, { type => SCALAR } ); | ||
|
||
# anything? | ||
return unless $hostname; | ||
|
||
# total length | ||
return if length($hostname) > 255; | ||
|
||
# each part | ||
my @parts = (split(/[.]/, $hostname)); | ||
return if any { length > 63 } @parts; | ||
return if any { ! /^[a-z0-9\-]+$/ } @parts; | ||
|
||
return $hostname; | ||
|
||
} | ||
|
||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
Munin::Common::Utils - Various utility functions | ||
=head1 SYNOPSIS | ||
use Munin::Common::Utils qw( ... ); | ||
=head1 SUBROUTINES | ||
=over | ||
=item B<is_valid_hostname($hostname)> | ||
Returns $hostname if it is syntactically valid, or an undef if not. | ||
=back | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.