Config-Validate
view release on metacpan or search on metacpan
function, class method, or instance method. If it is called as an
instance method, then the new type will also be added to that instance.
The parameters are the same as "add_type".
reset_default_types
The "reset_default_types" method removes all user defined types from the
base class. Any instances that are alread created will retain their
existing type configuration.
mkpath
This is a convenience function for people writing callbacks and user
defined type validation. It takes either an array or array reference and
returns a string that represents the path to a specific item in the
configuration. This might be useful if you're interested in having your
error messages be consistent with the rest of "Config::Validate". This
is available for export, but not exported by default. Note: this is a
function, not a method.
AUTHOR
Clayton O'Neill
lib/Config/Validate.pm view on Meta::CPAN
$self->add_type(%p);
}
if (defined $types{$p{name}}) {
_throw "Attempted to add type '$p{name}' that already exists";
}
my $type = clone(\%p);
delete $type->{name};
if (keys %$type == 0) {
_throw "No callbacks defined for type '$p{name}'";
}
$types{$p{name}} = $type;
return;
}
sub add_type {
my $self = shift;
my %p = _parse_add_type_params(@_);
if (defined $types[$$self]{$p{name}}) {
_throw "Attempted to add type '$p{name}' that already exists";
}
my $type = clone(\%p);
delete $type->{name};
if (keys %$type == 0) {
_throw "No callbacks defined for type '$p{name}'";
}
$types[$$self]{$p{name}} = $type;
return;
}
sub reset_default_types {
%types = %default_types;
return;
}
lib/Config/Validate.pm view on Meta::CPAN
instance. The parameters are the same as C<add_type>.
=head2 reset_default_types
The C<reset_default_types> method removes all user defined types from
the base class. Any instances that are alread created will retain
their existing type configuration.
=head2 mkpath
This is a convenience function for people writing callbacks and user
defined type validation. It takes either an array or array reference
and returns a string that represents the path to a specific item in
the configuration. This might be useful if you're interested in
having your error messages be consistent with the rest of
C<Config::Validate>. This is available for export, but not exported
by default. Note: this is a function, not a method.
=head1 AUTHOR
Clayton O'Neill
t/add_default_type.t view on Meta::CPAN
sub no_args :Test {
eval { Config::Validate::add_default_type(); };
like($@, qr/Mandatory parameter 'name' missing in call/i,
"No argument test");
return;
}
sub name_only :Test {
eval { Config::Validate->add_default_type(name => 'name_only'); };
like($@, qr/No callbacks defined for type 'name_only'/i,
"Name only test");
return;
}
sub validate_fail_on_type_with_init_hook :Test(2) {
my $init_ran = 0;
Config::Validate->add_default_type(name => 'init_hook',
init => sub { $init_ran++ },
);
t/add_type.t view on Meta::CPAN
eval { $self->{cv}->add_type(); };
like($@, qr/Mandatory parameter 'name' missing in call/i,
"No argument test");
return;
}
sub name_only :Test {
my ($self) = @_;
eval { $self->{cv}->add_type(name => 'name_only'); };
like($@, qr/No callbacks defined for type 'name_only'/i,
"Name only test");
return;
}
sub init_hook :Test(2) {
my ($self) = @_;
$self->{cv}->add_type(name => 'test_type',
init => $self->{callback},
);
( run in 0.554 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )