Skip to content

Commit

Permalink
new release, ver 7.84 with inheritance support
Browse files Browse the repository at this point in the history
  • Loading branch information
Al Newkirk committed Sep 20, 2012
1 parent ef5867f commit 504ff51
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -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"
}
Expand Down
8 changes: 7 additions & 1 deletion README
Expand Up @@ -3,7 +3,7 @@ NAME
Framework

VERSION
version 7.82
version 7.84

SYNOPSIS
package MyApp::User;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion README.mkdn
Expand Up @@ -4,7 +4,7 @@ Validation::Class - Self-Validating Object System and Data Validation Framework

# VERSION

version 7.82
version 7.84

# SYNOPSIS

Expand Down Expand Up @@ -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;


Expand Down
2 changes: 1 addition & 1 deletion dist.ini
Expand Up @@ -4,7 +4,7 @@ author = Al Newkirk <anewkirk@ana.io>
license = Perl_5
copyright_holder = Al Newkirk
copyright_year = 2011
version = 7.82
version = 7.84

[MetaResources]
homepage = https://github.com/alnewkirk/Validation-Class
Expand Down
35 changes: 29 additions & 6 deletions lib/Validation/Class.pm
Expand Up @@ -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 {
Expand Down Expand Up @@ -747,6 +765,11 @@ for extending the current class by attaching other L<Validation::Class> 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;
Expand Down
25 changes: 25 additions & 0 deletions 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;
29 changes: 29 additions & 0 deletions 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;

0 comments on commit 504ff51

Please sign in to comment.