From 504ff5134ddc337ae5190807cf07679116f6d865 Mon Sep 17 00:00:00 2001 From: Al Newkirk Date: Thu, 20 Sep 2012 19:51:28 -0400 Subject: [PATCH] new release, ver 7.84 with inheritance support --- CHANGES | 4 ++++ Makefile.PL | 2 +- README | 8 +++++++- README.mkdn | 7 ++++++- dist.ini | 2 +- lib/Validation/Class.pm | 35 ++++++++++++++++++++++++++++------ t/11-inheritence.t | 25 ++++++++++++++++++++++++ t/myapp/lib/MyApp/Container.pm | 29 ++++++++++++++++++++++++++++ 8 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 t/11-inheritence.t create mode 100644 t/myapp/lib/MyApp/Container.pm diff --git a/CHANGES b/CHANGES index a328794..19ca1b6 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ TODO (TBD) ? write new POD about cooperating with existing OO systems ? added a "TODO" section of POD to the main module +7.84 (2012-09-20) + * The import method has been modified to copy/merge meta-class configs based + on inheritance + 7.82 (2012-08-13) * The class method/functionality has been refactored (now using Class::Forward) * New invalid parameter structure error triggered when arrayrefs are discovered diff --git a/Makefile.PL b/Makefile.PL index 580da95..792e1aa 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -28,7 +28,7 @@ my %WriteMakefileArgs = ( "Module::Runtime" => 0, "utf8" => 0 }, - "VERSION" => "7.82", + "VERSION" => "7.84", "test" => { "TESTS" => "t/*.t t/regression/*.t t/regression/filters/*.t t/regression/validators/*.t" } diff --git a/README b/README index 9ae2b63..08cf230 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ NAME Framework VERSION - version 7.82 + version 7.84 SYNOPSIS package MyApp::User; @@ -296,6 +296,12 @@ KEYWORDS of applying roles to the current class mainly involve copying the role's methods and configuration. + NOTE: While the load/set functionality is not depreciated and will + remain part of this library, its uses are no longer recommended as there + are better ways to achieve the desired results. Additionally, the + following usage scenarios can be refactored using traditional + inheritance. + package MyApp; use Validation::Class; diff --git a/README.mkdn b/README.mkdn index f3d2ba1..497ccef 100644 --- a/README.mkdn +++ b/README.mkdn @@ -4,7 +4,7 @@ Validation::Class - Self-Validating Object System and Data Validation Framework # VERSION -version 7.82 +version 7.84 # SYNOPSIS @@ -359,6 +359,11 @@ for extending the current class by attaching other [Validation::Class](http://se as relatives, roles, plugins, etc. The process of applying roles to the current class mainly involve copying the role's methods and configuration. +NOTE: While the load/set functionality is not depreciated and will remain part +of this library, its uses are no longer recommended as there are better ways to +achieve the desired results. Additionally, the following usage scenarios can be +refactored using traditional inheritance. + package MyApp; diff --git a/dist.ini b/dist.ini index b25ae39..58df106 100644 --- a/dist.ini +++ b/dist.ini @@ -4,7 +4,7 @@ author = Al Newkirk license = Perl_5 copyright_holder = Al Newkirk copyright_year = 2011 -version = 7.82 +version = 7.84 [MetaResources] homepage = https://github.com/alnewkirk/Validation-Class diff --git a/lib/Validation/Class.pm b/lib/Validation/Class.pm index 9251ea7..7eef6f5 100644 --- a/lib/Validation/Class.pm +++ b/lib/Validation/Class.pm @@ -123,18 +123,36 @@ use Validation::Class::Prototype; sub import { my $caller = caller(0) || caller(1); + + strict->import; + warnings->import; + __PACKAGE__->export_to_level(1, @_); + if ($caller) { + # if requested, inherit config naturally via @ISA + + my $isa_string = "\@$caller\::ISA"; + my @caller_isa = eval $isa_string; + + @caller_isa = grep !/^$caller$/, @caller_isa; + + if (@caller_isa) { + + my $loader = $caller->can('set'); + $loader = $caller->can('load') unless $loader; + + if ($loader) { + $loader->($caller, { roles => [@caller_isa] }); + } + + } + return_class_proto $caller # create prototype instance when used } - - strict->import; - warnings->import; - - __PACKAGE__->export_to_level(1, @_); - + } sub initialize_validator { @@ -747,6 +765,11 @@ for extending the current class by attaching other L classes as relatives, roles, plugins, etc. The process of applying roles to the current class mainly involve copying the role's methods and configuration. +NOTE: While the load/set functionality is not depreciated and will remain part +of this library, its uses are no longer recommended as there are better ways to +achieve the desired results. Additionally, the following usage scenarios can be +refactored using traditional inheritance. + package MyApp; use Validation::Class; diff --git a/t/11-inheritence.t b/t/11-inheritence.t new file mode 100644 index 0000000..c395c5d --- /dev/null +++ b/t/11-inheritence.t @@ -0,0 +1,25 @@ +use Test::More; + +BEGIN { + use FindBin; + use lib $FindBin::Bin . "/myapp/lib"; +} + +package main; + +use MyApp::Container; + +my $v = MyApp::Container->new; + +ok $v, 'new obj'; +ok $v->proto->fields->{id}, 'obj has an id field'; +ok $v->proto->fields->{name}, 'obj has a name field'; +ok $v->proto->fields->{email}, 'obj has an email field'; +ok $v->proto->mixins->{basic}, 'obj has a basic mixin'; +ok $v->proto->mixins->{other}, 'obj has an other mixin'; +ok $v->proto->mixins->{email}, 'obj has an email mixin'; + +ok 1 == $v->id, "obj's id field was set and is ok"; +ok 'Boy' eq $v->name, "obj's name field was set and is ok"; + +done_testing; \ No newline at end of file diff --git a/t/myapp/lib/MyApp/Container.pm b/t/myapp/lib/MyApp/Container.pm new file mode 100644 index 0000000..877cf7c --- /dev/null +++ b/t/myapp/lib/MyApp/Container.pm @@ -0,0 +1,29 @@ +package MyApp::Container; + +use base 'MyApp::Test::Base'; + +use Validation::Class; + +mxn other => { + required => 1, + max_length => 255, + filters => [qw/trim strip/] +}; + +fld name => { + mixin => 'basic', + max_length => 255, + required => 0 +}; + +bld sub { + + my ($self) = @_; + + $self->name('Boy'); + + return $self; + +}; + +1; \ No newline at end of file