Validation-Class
view release on metacpan or search on metacpan
lib/Validation/Class/Exporter.pm view on Meta::CPAN
# ABSTRACT: Simple Exporter for Validation::Class Classes
package Validation::Class::Exporter;
use 5.008001;
use strict;
use warnings;
our $VERSION = '7.900059'; # VERSION
sub apply_spec {
my ($this, %args) = @_;
no strict 'refs';
no warnings 'once';
no warnings 'redefine';
my $parent = caller(0);
my @keywords = @{$args{keywords}} if $args{keywords};
my @routines = @{$args{routines}} if $args{routines};
my $settings = {@{$args{settings}}} if $args{settings};
*{"$parent\::import"} = sub {
my $child = caller(0);
*{"$child\::$_"} = *{"$parent\::$_"} for @{$args{keywords}};
*{"$child\::$_"} = *{"$parent\::$_"} for @{$args{routines}};
my $ISA = "$child\::ISA";
push @$ISA, 'Validation::Class'
unless grep { $_ eq 'Validation::Class' } @$ISA;
*{"$child\::$_"} = *{"Validation\::Class\::$_"}
for @Validation::Class::EXPORT;
strict->import;
warnings->import;
$child->load({@{$args{settings}}}) if $args{settings};
return $child;
};
return $this;
}
1;
__END__
=pod
=head1 NAME
Validation::Class::Exporter - Simple Exporter for Validation::Class Classes
=head1 VERSION
version 7.900059
=head1 SYNOPSIS
package MyApp::Validator;
use Validation::Class;
use Validation::Class::Exporter;
my @settings = (
classes => [
MyApp::Validator::DomainAlpha
MyApp::Validator::DomainBeta
]
);
Validation::Class::Exporter->apply_spec(
routines => ['thing'], # export additional routines as is
settings => [@settings] # passed to the `load` keyword in V::C
);
sub thing {
my $args = pop;
my $class = shift || caller;
# routine as a keyword
# ... do some thing
};
... in your application class:
package MyApp;
( run in 0.831 second using v1.01-cache-2.11-cpan-39bf76dae61 )