| Net-NSCA-Client documentation | Contained in the Net-NSCA-Client distribution. |
Net::NSCA::Client::Library - Types library
This documentation refers to version 0.009001
use Net::NSCA::Client::Library qw(Bytes); # This will import Bytes type into your namespace as well as some helpers # like to_Bytes and is_Bytes. See MooseX::Types for more information.
This module provides types for Net::NSCA::Client and family. This type library is not intended to be used my module in other distributions.
No methods.
Added in version 0.009; be sure to require this version for this feature.
This requires a string that does not have the internal UTF-8 flag enabled (because that means it is not a byte sequence). This provides a coercion to change the string into the UTF-8 byte sequence.
This specifies a hostname. This is validated using the
Data::Validate::Domain library with the
is_hostname function.
This type is exactly the same as the type PortNumber from
MooseX::Types::PortNumber.
This module is dependent on the following modules:
Douglas Christopher Wilson, <doug at somethingdoug.com>
Please report any bugs or feature requests to bug-net-nsca-client at rt.cpan.org,
or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-NSCA-Client.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
I highly encourage the submission of bugs and enhancements to my modules.
Copyright 2009 Douglas Christopher Wilson.
This program is free software; you can redistribute it and/or modify it under the terms of either:
| Net-NSCA-Client documentation | Contained in the Net-NSCA-Client distribution. |
package Net::NSCA::Client::Library; use 5.008001; use strict; use warnings 'all'; ############################################################################### # METADATA our $AUTHORITY = 'cpan:DOUGDUDE'; our $VERSION = '0.009001'; ############################################################################### # MOOSE TYPE DECLARATIONS use MooseX::Types 0.08 -declare => [qw( Bytes Hostname Timeout )]; ############################################################################### # MOOSE TYPES use MooseX::Types::Moose qw(Int Str); use MooseX::Types::PortNumber qw(PortNumber); ############################################################################### # MODULES use Data::Validate::Domain 0.02; ############################################################################### # ALL IMPORTS BEFORE THIS WILL BE ERASED use namespace::clean 0.04 -except => [qw(meta)]; ############################################################################### # TYPE DEFINITIONS subtype Bytes, as Str, where { !utf8::is_utf8($_) }, message { 'Cannot have internal utf8 flag on' }; coerce Bytes, from Str, via { _turn_off_utf8($_) }; subtype Hostname, as Str, where { Data::Validate::Domain::is_hostname($_) }, message { 'Must be a valid hostname' }; subtype Timeout, as Int, where { $_ > 0 }, message { 'Timeout must be greater than 0' }; # Add external types as types from this package _add_external_type( PortNumber => PortNumber, ); ############################################################################### # PRIVATE FUNCTIONS sub _add_external_type { my (%pairs) = @_; TYPE: for my $name (keys %pairs) { # Add an entry to the type_storage where the key is simply the name # of the type (a simple string) and the value is the string of the # type location. __PACKAGE__->type_storage->{$name} = "$pairs{$name}"; } return; } sub _turn_off_utf8 { my ($str) = @_; if (utf8::is_utf8($str)) { utf8::encode($str); } return $str; } 1; __END__