| 1 | # ABSTRACT: Simple Exporter for Validation::Class Classes | ||
| 2 | |||
| 3 | package Validation::Class::Exporter; | ||
| 4 | { | ||
| 5 | $Validation::Class::Exporter::VERSION = '7.10_01'; | ||
| 6 | } | ||
| 7 | |||
| 8 | use 5.008001; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | our $VERSION = '7.10_01'; # VERSION | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | sub apply_spec { | ||
| 18 | |||
| 19 | my ($this, %args) = @_; | ||
| 20 | |||
| 21 | no strict 'refs'; | ||
| 22 | no warnings 'once'; | ||
| 23 | no warnings 'redefine'; | ||
| 24 | |||
| 25 | my $parent = caller(0); | ||
| 26 | |||
| 27 | my @keywords = @{ $args{keywords} } if $args{keywords}; | ||
| 28 | |||
| 29 | my @routines = @{ $args{routines} } if $args{routines}; | ||
| 30 | |||
| 31 | my $settings = { @{ $args{settings} } } if $args{settings}; | ||
| 32 | |||
| 33 | *{"$parent\::import"} = sub { | ||
| 34 | |||
| 35 | my $child = caller(0); | ||
| 36 | |||
| 37 | *{"$child\::$_"} = *{"$parent\::$_"} for @keywords; | ||
| 38 | |||
| 39 | *{"$child\::$_"} = *{"$parent\::$_"} for @routines; | ||
| 40 | |||
| 41 | my $ISA = "$child\::ISA"; | ||
| 42 | |||
| 43 | push @$ISA, 'Validation::Class' | ||
| 44 | unless grep { $_ eq 'Validation::Class' } @$ISA; | ||
| 45 | |||
| 46 | *{"$child\::$_"} = *{"Validation\::Class\::$_"} | ||
| 47 | for @Validation::Class::EXPORT; | ||
| 48 | |||
| 49 | strict->import; | ||
| 50 | warnings->import; | ||
| 51 | |||
| 52 | $child->load($settings) if $settings; | ||
| 53 | |||
| 54 | return $child; | ||
| 55 | |||
| 56 | }; | ||
| 57 | |||
| 58 | return $this; | ||
| 59 | |||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | __END__ |