Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

resolved merge conflict from github repo

  • Loading branch information...
commit 395fe2facf2a11f8cc7f4c9724ef56b5191734f3 2 parents dcf4225 + 504ff51
Al Newkirk authored
4 CHANGES
@@ -5,6 +5,10 @@ TODO (TBD)
5 5 ? write new POD about cooperating with existing OO systems
6 6 ? added a "TODO" section of POD to the main module
7 7
  8 +7.84 (2012-09-20)
  9 + * The import method has been modified to copy/merge meta-class configs based
  10 + on inheritance
  11 +
8 12 7.82 (2012-08-13)
9 13 * The class method/functionality has been refactored (now using Class::Forward)
10 14 * New invalid parameter structure error triggered when arrayrefs are discovered
4 Makefile.PL
@@ -21,14 +21,14 @@ my %WriteMakefileArgs = (
21 21 "NAME" => "Validation::Class",
22 22 "PREREQ_PM" => {
23 23 "Carp" => 0,
24   - "Class::Forward" => 0,
  24 + "Class::Forward" => "0.04",
25 25 "Hash::Flatten" => 0,
26 26 "Hash::Merge" => 0,
27 27 "Module::Find" => 0,
28 28 "Module::Runtime" => 0,
29 29 "utf8" => 0
30 30 },
31   - "VERSION" => "7.831",
  31 + "VERSION" => "7.84",
32 32 "test" => {
33 33 "TESTS" => "t/*.t t/regression/*.t t/regression/filters/*.t t/regression/validators/*.t"
34 34 }
328 README
@@ -3,41 +3,41 @@ NAME
3 3 Framework
4 4
5 5 VERSION
6   - version 7.831
  6 + version 7.84
7 7
8 8 SYNOPSIS
9 9 package MyApp::User;
10   -
  10 +
11 11 use Validation::Class;
12   -
  12 +
13 13 mixin basic => {
14 14 required => 1,
15 15 max_length => 255,
16 16 filters => [qw/trim strip/]
17   - };
18   -
  17 + };
  18 +
19 19 field login => {
20 20 mixin => 'basic',
21 21 min_length => 5
22 22 };
23   -
  23 +
24 24 field password => {
25 25 mixin => 'basic',
26 26 min_length => 5,
27 27 min_symbols => 1
28 28 };
29   -
  29 +
30 30 package main;
31   -
  31 +
32 32 my $user = MyApp::User->new(login => 'admin', password => 'secr3t');
33   -
  33 +
34 34 unless ($user->validate('login', 'password')) {
35   -
  35 +
36 36 # do something with the errors,
37 37 # e.g. print $user->errors_to_string
38   -
  38 +
39 39 }
40   -
  40 +
41 41 1;
42 42
43 43 Validation::Class is a data validation framework and simple object
@@ -98,17 +98,17 @@ KEYWORDS
98 98 systems such as Moose, Mouse, Moo, Mo, etc.
99 99
100 100 package MyApp::User;
101   -
  101 +
102 102 use Validate::Class;
103   -
  103 +
104 104 attribute 'bothered' => 1;
105   -
  105 +
106 106 attribute 'attitude' => sub {
107   -
108   - return $self->bothered ? 1 : 0
109   -
  107 +
  108 + return $self->bothered ? 1 : 0
  109 +
110 110 };
111   -
  111 +
112 112 1;
113 113
114 114 The attribute keyword takes two arguments, the attribute name and a
@@ -120,34 +120,34 @@ KEYWORDS
120 120 modern-day OO systems.
121 121
122 122 package MyApp::User;
123   -
  123 +
124 124 use Validation::Class;
125   -
  125 +
126 126 build sub {
127   -
  127 +
128 128 my ($self, %args) = @_;
129   -
  129 +
130 130 # ... do something
131   -
  131 +
132 132 };
133   -
  133 +
134 134 # die like a Moose
135   -
  135 +
136 136 use Carp;
137   -
  137 +
138 138 build sub {
139   -
  139 +
140 140 my ($self, %args) = @_;
141   -
  141 +
142 142 my @attributes = qw();
143   -
  143 +
144 144 foreach my $attribute (@attributes) {
145   -
  145 +
146 146 confess "Attribute ($attribute) is required"
147 147 unless $self->$attribute;
148   -
  148 +
149 149 }
150   -
  150 +
151 151 };
152 152
153 153 The build keyword takes one argument, a coderef which is passed the
@@ -160,40 +160,40 @@ KEYWORDS
160 160 custom directive extension packages to be used in all your classes.
161 161
162 162 package MyApp::Directives;
163   -
  163 +
164 164 use Validation::Class;
165 165 use Data::Validate::Email;
166   -
  166 +
167 167 directive 'is_email' => sub {
168   -
  168 +
169 169 my ($dir, $value, $field, $self) = @_;
170   -
  170 +
171 171 my $validator = Data::Validate::Email->new;
172   -
  172 +
173 173 unless ($validator->is_email($value)) {
174   -
  174 +
175 175 my $handle = $field->{label} || $field->{name};
176   -
  176 +
177 177 $field->{errors}->add("$handle must be a valid email address");
178   -
  178 +
179 179 return 0;
180   -
  180 +
181 181 }
182   -
  182 +
183 183 return 1;
184   -
  184 +
185 185 };
186   -
  186 +
187 187 package MyApp::User;
188   -
  188 +
189 189 use Validate::Class;
190 190 use MyApp::Directives;
191   -
  191 +
192 192 field 'email' => {
193 193 is_email => 1,
194 194 ...
195 195 };
196   -
  196 +
197 197 1;
198 198
199 199 The directive keyword takes two arguments, the name of the directive and
@@ -213,9 +213,9 @@ KEYWORDS
213 213 name expected to be passed to your validation class.
214 214
215 215 package MyApp::User;
216   -
  216 +
217 217 use Validation::Class;
218   -
  218 +
219 219 field 'login' => {
220 220 required => 1,
221 221 min_length => 1,
@@ -237,17 +237,17 @@ KEYWORDS
237 237 max_length => 255,
238 238 ...
239 239 };
240   -
  240 +
241 241 field 'preference.send_reminders' => {
242 242 required => 1,
243 243 max_length => 1,
244 244 ...
245 245 };
246   -
  246 +
247 247 my $value = $self->login;
248   -
  248 +
249 249 $self->login($new_value);
250   -
  250 +
251 251 $self->preference_send_reminders;
252 252
253 253 Protip: Field directives are used to validate scalar and array data.
@@ -262,26 +262,26 @@ KEYWORDS
262 262 extension packages to be used in all your classes.
263 263
264 264 package MyApp::Directives;
265   -
  265 +
266 266 use Validation::Class;
267   -
  267 +
268 268 filter 'flatten' => sub {
269   -
  269 +
270 270 $_[0] =~ s/[\t\r\n]+/ /g;
271 271 $_[0] # return
272   -
  272 +
273 273 };
274   -
  274 +
275 275 package MyApp::User;
276   -
  276 +
277 277 use Validate::Class;
278 278 use MyApp::Directives;
279   -
  279 +
280 280 field 'description' => {
281 281 filters => ['trim', 'flatten'],
282 282 ...
283 283 };
284   -
  284 +
285 285 1;
286 286
287 287 The filter keyword takes two arguments, the name of the filter and a
@@ -296,18 +296,24 @@ KEYWORDS
296 296 of applying roles to the current class mainly involve copying the role's
297 297 methods and configuration.
298 298
299   - package MyApp;
  299 + NOTE: While the load/set functionality is not depreciated and will
  300 + remain part of this library, its uses are no longer recommended as there
  301 + are better ways to achieve the desired results. Additionally, the
  302 + following usage scenarios can be refactored using traditional
  303 + inheritance.
300 304
  305 + package MyApp;
  306 +
301 307 use Validation::Class;
302   -
  308 +
303 309 # load stuff (extend MyApp)
304   -
  310 +
305 311 load {
306   -
  312 +
307 313 # run package commands
308   -
  314 +
309 315 };
310   -
  316 +
311 317 1;
312 318
313 319 The "load.classes" option, can be a constant or arrayref and uses
@@ -319,26 +325,26 @@ KEYWORDS
319 325 This option accepts a constant or an arrayref of constants.
320 326
321 327 package MyApp;
322   -
  328 +
323 329 use Validation::Class;
324   -
  330 +
325 331 # load all child classes
326   -
  332 +
327 333 load {
328 334 classes => [
329 335 __PACKAGE__
330 336 ]
331 337 };
332   -
  338 +
333 339 package main;
334   -
  340 +
335 341 my $app = MyApp->new;
336   -
  342 +
337 343 my $rel = $app->class('relative'); # new MyApp::Relative object
338   -
  344 +
339 345 my $rel = $app->class('data_source'); # MyApp::DataSource
340 346 my $rel = $app->class('datasource-first'); # MyApp::Datasource::First
341   -
  347 +
342 348 1;
343 349
344 350 The "load.plugins" option is used to load plugins that support
@@ -351,16 +357,16 @@ KEYWORDS
351 357 constant or an arrayref of constants.
352 358
353 359 package MyVal;
354   -
  360 +
355 361 use Validation::Class;
356   -
  362 +
357 363 load {
358 364 plugins => [
359 365 'CPANPlugin', # Validation::Class::Plugin::CPANPlugin
360 366 '+MyVal::Plugin'
361 367 ]
362 368 };
363   -
  369 +
364 370 1;
365 371
366 372 The "load.roles" option is used to load and inherit functionality from
@@ -369,24 +375,24 @@ KEYWORDS
369 375 accepts a constant or an arrayref of constants.
370 376
371 377 package MyVal::User;
372   -
  378 +
373 379 use Validation::Class;
374   -
  380 +
375 381 load {
376 382 roles => [
377 383 'MyVal::Person'
378 384 ]
379 385 };
380   -
  386 +
381 387 1;
382 388
383 389 Purely for the sake of aesthetics we have designed an alternate syntax
384 390 for executing load/set commands, the syntax is as follows:
385 391
386 392 package MyVal::User;
387   -
  393 +
388 394 use Validation::Class;
389   -
  395 +
390 396 load roles => ['MyVal::Person'];
391 397 load classes => [__PACKAGE__];
392 398 load plugins => [
@@ -401,35 +407,35 @@ KEYWORDS
401 407 required data necessary to proceed.
402 408
403 409 package MyApp::User;
404   -
  410 +
405 411 use Validation::Class;
406   -
  412 +
407 413 method 'register' => {
408   -
  414 +
409 415 input => ['name', '+email', 'login', '+password'],
410 416 output => ['+id'], # optional output validation, dies on failure
411 417 using => sub {
412   -
  418 +
413 419 my ($self, @args) = @_;
414   -
  420 +
415 421 # .... do something registrationy
416   -
  422 +
417 423 $self->id(...); # set the ID field for output validation
418   -
  424 +
419 425 return $self;
420   -
  426 +
421 427 }
422   -
  428 +
423 429 };
424   -
  430 +
425 431 package main;
426   -
  432 +
427 433 my $user = MyApp::User->new(params => $params);
428   -
  434 +
429 435 if ($user->register) {
430 436 ...
431 437 }
432   -
  438 +
433 439 1;
434 440
435 441 The method keyword takes two arguments, the name of the method to be
@@ -460,16 +466,16 @@ KEYWORDS
460 466 directives.
461 467
462 468 package MyApp::User;
463   -
  469 +
464 470 use Validation::Class;
465   -
  471 +
466 472 mixin 'constrain' => {
467 473 required => 1,
468 474 min_length => 1,
469 475 max_length => 255,
470 476 ...
471 477 };
472   -
  478 +
473 479 # e.g.
474 480 field 'login' => {
475 481 mixin => 'constrain',
@@ -487,39 +493,39 @@ KEYWORDS
487 493 returned class object it constructs.
488 494
489 495 package MyApp::User::Input;
490   -
  496 +
491 497 use MyApp::User; # a Moose class
492   -
  498 +
493 499 use Validation::Class;
494   -
  500 +
495 501 field login => {
496 502 required => 1,
497 503 };
498   -
  504 +
499 505 field password => {
500 506 required => 1,
501 507 };
502   -
  508 +
503 509 object _build_user => {
504   -
  510 +
505 511 type => 'MyApp::User',
506   -
  512 +
507 513 # init => 'new', # defaults to new
508 514 # args => [qw/login password/], # defaults to all fields
509 515 # list => 'hash' # defaults to list
510   -
  516 +
511 517 };
512   -
  518 +
513 519 package main;
514   -
  520 +
515 521 my $user_input = MyApp::User::Input->new(params => $params);
516   -
  522 +
517 523 if ($user_input->validate('login', 'password')) {
518   -
  524 +
519 525 my $user = $user_input->_build_user;
520   -
  526 +
521 527 # ...
522   -
  528 +
523 529 }
524 530
525 531 The object keyword takes two arguments, an object builder name and a
@@ -529,14 +535,14 @@ KEYWORDS
529 535
530 536 # class to construct
531 537 type => 'ClassName',
532   -
  538 +
533 539 # optional: constructor name (defaults to new)
534 540 init => 'new',
535   -
  541 +
536 542 # optional: arrayref of field names or a coderef which returns arguments for
537 543 # the constructor (defaults to all fields)
538 544 args => sub {}
539   -
  545 +
540 546 # optional: if supplying an arrayref of fields to the args option, this
541 547 # option determines how the parameters will be supplied to the constructor,
542 548 # valid options are 'hash' or 'list' (defaults to list)
@@ -548,15 +554,15 @@ KEYWORDS
548 554 routines that validate data relevant to a specific action.
549 555
550 556 package MyApp::User;
551   -
  557 +
552 558 use Validation::Class;
553   -
  559 +
554 560 profile 'signup' => sub {
555   -
  561 +
556 562 my ($self, @args) = @_;
557   -
  563 +
558 564 # ... do other stuff
559   -
  565 +
560 566 return $self->validate(qw(
561 567 +name
562 568 +email
@@ -565,17 +571,17 @@ KEYWORDS
565 571 +password
566 572 +password_confirmation
567 573 ));
568   -
  574 +
569 575 };
570   -
  576 +
571 577 package main;
572   -
  578 +
573 579 my $user = MyApp::User->new(params => $params);
574   -
  580 +
575 581 unless ($user->validate_profile('signup')) {
576   -
  582 +
577 583 die $user->errors_to_string;
578   -
  584 +
579 585 }
580 586
581 587 The profile keyword takes two arguments, a profile name and coderef
@@ -590,21 +596,21 @@ METHODS
590 596 hooking into the instantiation process.
591 597
592 598 package MyApp;
593   -
  599 +
594 600 use Validation::Class;
595   -
  601 +
596 602 # optionally
597   -
  603 +
598 604 build sub {
599   -
  605 +
600 606 my ($self, @args) = @_; # is instantiated
601   -
  607 +
602 608 };
603   -
  609 +
604 610 package main;
605   -
  611 +
606 612 my $app = MyApp->new;
607   -
  613 +
608 614 ...
609 615
610 616 prototype
@@ -615,15 +621,15 @@ METHODS
615 621 Validation::Class.
616 622
617 623 package MyApp;
618   -
  624 +
619 625 use Validation::Class;
620   -
  626 +
621 627 package main;
622   -
  628 +
623 629 my $app = MyApp->new;
624   -
  630 +
625 631 my $prototype = $app->prototype;
626   -
  632 +
627 633 ...
628 634
629 635 THE PROTOTYPE CLASS
@@ -642,14 +648,14 @@ THE PROTOTYPE CLASS
642 648 methods.
643 649
644 650 package MyApp::User;
645   -
  651 +
646 652 use Validation::Class;
647   -
  653 +
648 654 package main;
649   -
  655 +
650 656 my $user = MyApp::User->new;
651 657 my $proto = $user->prototype;
652   -
  658 +
653 659 $proto->error_count # same as calling $self->error_count
654 660
655 661 THE OBJECT SYSTEM
@@ -664,60 +670,60 @@ THE OBJECT SYSTEM
664 670 same regardless of the existing system):
665 671
666 672 # USING MOOSE AS YOUR PRIMARY OO SYSTEM
667   -
  673 +
668 674 package MyApp;
669   -
  675 +
670 676 use Moose;
671 677 use Validation::Class '!has'; # in cooperative mode, dont export has()
672   -
  678 +
673 679 # you must run initialization routines yourself ...
674 680 # specifying it in a BUILD routine will run it automatically
675   -
  681 +
676 682 sub BUILD {
677   -
  683 +
678 684 my ($self, $args) = @_;
679   -
  685 +
680 686 $self->initialize_validator(
681 687 params => $args->{params}
682 688 );
683   -
  689 +
684 690 }
685   -
  691 +
686 692 field login => {
687 693 min_length => 5
688 694 max_length => 50
689 695 };
690   -
  696 +
691 697 field password => {
692 698 min_length => 8,
693 699 min_symbols => 1
694 700 max_length => 50
695 701 };
696   -
  702 +
697 703 # USING MOOSE AS YOUR SECONDARY/BACKUP OO SYSTEM
698   -
  704 +
699 705 package MyApp;
700   -
  706 +
701 707 use Validation::Class '!has'; # avoids has() keyword clash
702 708 use Moose;
703   -
  709 +
704 710 field login => {
705 711 min_length => 5
706 712 max_length => 50
707 713 };
708   -
  714 +
709 715 field password => {
710 716 min_length => 8,
711 717 min_symbols => 1
712 718 max_length => 50
713 719 };
714   -
  720 +
715 721 has database => (
716 722 is => 'rw',
717 723 isa => 'DBI::db',
718 724 ...
719 725 );
720   -
  726 +
721 727 1;
722 728
723 729 This cooperation works by simply detecting the existence of a method
281 README.mkdn
Source Rendered
@@ -4,46 +4,56 @@ Validation::Class - Self-Validating Object System and Data Validation Framework
4 4
5 5 # VERSION
6 6
7   -version 7.831
  7 +version 7.84
8 8
9 9 # SYNOPSIS
10 10
11 11 package MyApp::User;
  12 +
12 13
13 14 use Validation::Class;
  15 +
14 16
15 17 mixin basic => {
16 18 required => 1,
17 19 max_length => 255,
18 20 filters => [qw/trim strip/]
19   - };
  21 + };
  22 +
20 23
21 24 field login => {
22 25 mixin => 'basic',
23 26 min_length => 5
24 27 };
  28 +
25 29
26 30 field password => {
27 31 mixin => 'basic',
28 32 min_length => 5,
29 33 min_symbols => 1
30 34 };
  35 +
31 36
32 37 package main;
  38 +
33 39
34 40 my $user = MyApp::User->new(login => 'admin', password => 'secr3t');
  41 +
35 42
36 43 unless ($user->validate('login', 'password')) {
  44 +
37 45
38 46 # do something with the errors,
39 47 # e.g. print $user->errors_to_string
  48 +
40 49
41 50 }
  51 +
42 52
43 53 1;
44 54
45 55 Validation::Class is a data validation framework and simple object system. It
46   -allows you to model data and construct objects with focus on structure,
  56 +allows you to model data and construct objects with focus on structure,
47 57 reusability and data validation. It expects user input errors (without dying),
48 58 validation only occurs when you ask it to. Validation::Class classes are designed
49 59 to ensure consistency and promote reuse of data validation rules.
@@ -100,16 +110,22 @@ minimalistic variant of what you may have encountered in other object systems
100 110 such as [Moose](http://search.cpan.org/perldoc?Moose), [Mouse](http://search.cpan.org/perldoc?Mouse), [Moo](http://search.cpan.org/perldoc?Moo), [Mo](http://search.cpan.org/perldoc?Mo), etc.
101 111
102 112 package MyApp::User;
  113 +
103 114
104 115 use Validate::Class;
  116 +
105 117
106 118 attribute 'bothered' => 1;
  119 +
107 120
108 121 attribute 'attitude' => sub {
  122 +
109 123
110   - return $self->bothered ? 1 : 0
  124 + return $self->bothered ? 1 : 0
  125 +
111 126
112 127 };
  128 +
113 129
114 130 1;
115 131
@@ -122,33 +138,47 @@ The build keyword (or bld) registers a coderef to be run at instantiation much
122 138 in the same way the common BUILD routine is used in modern-day OO systems.
123 139
124 140 package MyApp::User;
  141 +
125 142
126 143 use Validation::Class;
  144 +
127 145
128 146 build sub {
  147 +
129 148
130 149 my ($self, %args) = @_;
  150 +
131 151
132 152 # ... do something
  153 +
133 154
134 155 };
  156 +
135 157
136 158 # die like a Moose
  159 +
137 160
138 161 use Carp;
  162 +
139 163
140 164 build sub {
  165 +
141 166
142 167 my ($self, %args) = @_;
  168 +
143 169
144 170 my @attributes = qw();
  171 +
145 172
146 173 foreach my $attribute (@attributes) {
  174 +
147 175
148 176 confess "Attribute ($attribute) is required"
149 177 unless $self->$attribute;
  178 +
150 179
151 180 }
  181 +
152 182
153 183 };
154 184
@@ -163,39 +193,54 @@ table before runtime and is ideal for creating custom directive extension
163 193 packages to be used in all your classes.
164 194
165 195 package MyApp::Directives;
  196 +
166 197
167 198 use Validation::Class;
168 199 use Data::Validate::Email;
  200 +
169 201
170 202 directive 'is_email' => sub {
  203 +
171 204
172 205 my ($dir, $value, $field, $self) = @_;
  206 +
173 207
174 208 my $validator = Data::Validate::Email->new;
  209 +
175 210
176 211 unless ($validator->is_email($value)) {
  212 +
177 213
178 214 my $handle = $field->{label} || $field->{name};
  215 +
179 216
180 217 $field->{errors}->add("$handle must be a valid email address");
  218 +
181 219
182 220 return 0;
  221 +
183 222
184 223 }
  224 +
185 225
186 226 return 1;
  227 +
187 228
188 229 };
  230 +
189 231
190 232 package MyApp::User;
  233 +
191 234
192 235 use Validate::Class;
193 236 use MyApp::Directives;
  237 +
194 238
195 239 field 'email' => {
196 240 is_email => 1,
197 241 ...
198 242 };
  243 +
199 244
200 245 1;
201 246
@@ -217,8 +262,10 @@ in code. The field name should correspond with the parameter name expected to
217 262 be passed to your validation class.
218 263
219 264 package MyApp::User;
  265 +
220 266
221 267 use Validation::Class;
  268 +
222 269
223 270 field 'login' => {
224 271 required => 1,
@@ -241,21 +288,25 @@ underscore.
241 288 max_length => 255,
242 289 ...
243 290 };
  291 +
244 292
245 293 field 'preference.send_reminders' => {
246 294 required => 1,
247 295 max_length => 1,
248 296 ...
249 297 };
  298 +
250 299
251 300 my $value = $self->login;
  301 +
252 302
253 303 $self->login($new_value);
  304 +
254 305
255 306 $self->preference_send_reminders;
256 307
257 308 Protip: Field directives are used to validate scalar and array data. Don't use
258   -fields to store and validate objects. Please see the \*has\* keyword instead or
  309 +fields to store and validate objects. Please see the *has* keyword instead or
259 310 use an object system with type constraints like [Moose](http://search.cpan.org/perldoc?Moose).
260 311
261 312 ## filter
@@ -266,25 +317,33 @@ runtime and is ideal for creating custom directive extension packages to be used
266 317 in all your classes.
267 318
268 319 package MyApp::Directives;
  320 +
269 321
270 322 use Validation::Class;
  323 +
271 324
272 325 filter 'flatten' => sub {
  326 +
273 327
274 328 $_[0] =~ s/[\t\r\n]+/ /g;
275 329 $_[0] # return
  330 +
276 331
277 332 };
  333 +
278 334
279 335 package MyApp::User;
  336 +
280 337
281 338 use Validate::Class;
282 339 use MyApp::Directives;
  340 +
283 341
284 342 field 'description' => {
285 343 filters => ['trim', 'flatten'],
286 344 ...
287 345 };
  346 +
288 347
289 348 1;
290 349
@@ -300,17 +359,28 @@ for extending the current class by attaching other [Validation::Class](http://se
300 359 as relatives, roles, plugins, etc. The process of applying roles to the current
301 360 class mainly involve copying the role's methods and configuration.
302 361
  362 +NOTE: While the load/set functionality is not depreciated and will remain part
  363 +of this library, its uses are no longer recommended as there are better ways to
  364 +achieve the desired results. Additionally, the following usage scenarios can be
  365 +refactored using traditional inheritance.
  366 +
303 367 package MyApp;
  368 +
304 369
305 370 use Validation::Class;
  371 +
306 372
307 373 # load stuff (extend MyApp)
  374 +
308 375
309 376 load {
  377 +
310 378
311 379 # run package commands
  380 +
312 381
313 382 };
  383 +
314 384
315 385 1;
316 386
@@ -323,29 +393,37 @@ often referred to as relatives. This option accepts a constant or an arrayref of
323 393 constants.
324 394
325 395 package MyApp;
  396 +
326 397
327 398 use Validation::Class;
  399 +
328 400
329 401 # load all child classes
  402 +
330 403
331 404 load {
332 405 classes => [
333 406 __PACKAGE__
334 407 ]
335 408 };
  409 +
336 410
337 411 package main;
  412 +
338 413
339 414 my $app = MyApp->new;
  415 +
340 416
341 417 my $rel = $app->class('relative'); # new MyApp::Relative object
  418 +
342 419
343 420 my $rel = $app->class('data_source'); # MyApp::DataSource
344 421 my $rel = $app->class('datasource-first'); # MyApp::Datasource::First
  422 +
345 423
346 424 1;
347 425
348   -The `load.plugins` option is used to load plugins that support Validation::Class.
  426 +The `load.plugins` option is used to load plugins that support Validation::Class.
349 427 A Validation::Class plugin is little more than a class that implements a "new"
350 428 method that extends the associated validation class object. As usual, an official
351 429 Validation::Class plugin can be referred to using shorthand while custom plugins
@@ -354,8 +432,10 @@ more about plugins at [Validation::Class::Intro](http://search.cpan.org/perldoc?
354 432 constant or an arrayref of constants.
355 433
356 434 package MyVal;
  435 +
357 436
358 437 use Validation::Class;
  438 +
359 439
360 440 load {
361 441 plugins => [
@@ -363,6 +443,7 @@ constant or an arrayref of constants.
363 443 '+MyVal::Plugin'
364 444 ]
365 445 };
  446 +
366 447
367 448 1;
368 449
@@ -372,14 +453,17 @@ class can be used as a role with this option. This option accepts a constant or
372 453 an arrayref of constants.
373 454
374 455 package MyVal::User;
  456 +
375 457
376 458 use Validation::Class;
  459 +
377 460
378 461 load {
379 462 roles => [
380 463 'MyVal::Person'
381 464 ]
382 465 };
  466 +
383 467
384 468 1;
385 469
@@ -387,15 +471,17 @@ Purely for the sake of aesthetics we have designed an alternate syntax for
387 471 executing load/set commands, the syntax is as follows:
388 472
389 473 package MyVal::User;
  474 +
390 475
391 476 use Validation::Class;
  477 +
392 478
393 479 load roles => ['MyVal::Person'];
394 480 load classes => [__PACKAGE__];
395 481 load plugins => [
396 482 'CPANPlugin', # Validation::Class::Plugin::CPANPlugin
397 483 '+MyVal::Plugin'
398   - ];
  484 + ];
399 485
400 486 ## method
401 487
@@ -405,34 +491,47 @@ validation rules and profiles to ensure a method has the required data necessary
405 491 to proceed.
406 492
407 493 package MyApp::User;
  494 +
408 495
409 496 use Validation::Class;
  497 +
410 498
411 499 method 'register' => {
  500 +
412 501
413 502 input => ['name', '+email', 'login', '+password'],
414 503 output => ['+id'], # optional output validation, dies on failure
415 504 using => sub {
  505 +
416 506
417 507 my ($self, @args) = @_;
  508 +
418 509
419 510 # .... do something registrationy
  511 +
420 512
421 513 $self->id(...); # set the ID field for output validation
  514 +
422 515
423 516 return $self;
  517 +
424 518
425 519 }
  520 +
426 521
427 522 };
  523 +
428 524
429 525 package main;
  526 +
430 527
431 528 my $user = MyApp::User->new(params => $params);
  529 +
432 530
433 531 if ($user->register) {
434 532 ...
435 533 }
  534 +
436 535
437 536 1;
438 537
@@ -453,7 +552,7 @@ assumption that given successfully validated input a routine's output should be
453 552 predictable and if an error occurs it is most-likely a program error as opposed
454 553 to a user error.
455 554
456   -See the ignore\_failure and report\_failure switch to control how method input
  555 +See the ignore_failure and report_failure switch to control how method input
457 556 validation failures are handled.
458 557
459 558 ## mixin
@@ -463,8 +562,10 @@ applied to any field using the mixin directive. Mixin directives are processed
463 562 first so existing field directives will override the mixed-in directives.
464 563
465 564 package MyApp::User;
  565 +
466 566
467 567 use Validation::Class;
  568 +
468 569
469 570 mixin 'constrain' => {
470 571 required => 1,
@@ -472,6 +573,7 @@ first so existing field directives will override the mixed-in directives.
472 573 max_length => 255,
473 574 ...
474 575 };
  576 +
475 577
476 578 # e.g.
477 579 field 'login' => {
@@ -491,38 +593,52 @@ method does not cache or otherwise store the returned class object it
491 593 constructs.
492 594
493 595 package MyApp::User::Input;
  596 +
494 597
495 598 use MyApp::User; # a Moose class
  599 +
496 600
497 601 use Validation::Class;
  602 +
498 603
499 604 field login => {
500 605 required => 1,
501 606 };
  607 +
502 608
503 609 field password => {
504 610 required => 1,
505 611 };
  612 +
506 613
507 614 object _build_user => {
  615 +
508 616
509 617 type => 'MyApp::User',
  618 +
510 619
511 620