=over 4
-=item L<Moose::Cookbook::Recipe1>
+=item L<Moose::Cookbook::Recipe1> - The (always classic) B<Point> example
-=item L<Moose::Cookbook::Recipe2>
+=item L<Moose::Cookbook::Recipe2> - A simple B<BankAccount> example
-=item L<Moose::Cookbook::Recipe3>
+=item L<Moose::Cookbook::Recipe3> - A lazy B<BinaryTree> example
-=item L<Moose::Cookbook::Recipe4>
+=item L<Moose::Cookbook::Recipe4> - Subtypes, and modeling a simple B<Company> class hierarchy
-=item L<Moose::Cookbook::Recipe5>
+=item L<Moose::Cookbook::Recipe5> - More subtypes, coercion in a B<Request> class
=back
=pod
-==> AtLeast.pm <==
-package BAST::Web::Model::Constraint::AtLeast;
-
-use strict;
-use warnings;
-use Moose;
-use BAST::Web::Model::Constraint;
-
-extends 'BAST::Web::Model::Constraint';
-
-has 'value' => (isa => 'Num', is => 'ro');
-
-sub validate {
- my ($self, $field) = @_;
- if ($self->validation_value($field) >= $self->value) {
- return undef;
- } else {
- return $self->error_message;
- }
-}
-
-sub error_message { 'must be at least '.shift->value; }
-
-1;
-
-==> NoMoreThan.pm <==
-package BAST::Web::Model::Constraint::NoMoreThan;
-
-use strict;
-use warnings;
-use Moose;
-use BAST::Web::Model::Constraint;
-
-extends 'BAST::Web::Model::Constraint';
-
-has 'value' => (isa => 'Num', is => 'ro');
-
-sub validate {
- my ($self, $field) = @_;
- if ($self->validation_value($field) <= $self->value) {
- return undef;
- } else {
- return $self->error_message;
- }
-}
-
-sub error_message { 'must be no more than '.shift->value; }
-
-1;
-
-==> OnLength.pm <==
-package BAST::Web::Model::Constraint::OnLength;
-
-use strict;
-use warnings;
-use Moose;
-
-has 'units' => (isa => 'Str', is => 'ro');
-
-override 'value' => sub {
- return length(super());
-};
-
-override 'error_message' => sub {
- my $self = shift;
- return super().' '.$self->units;
-};
-
-1;
-
-package BAST::Web::Model::Constraint::LengthNoMoreThan;
-
-use strict;
-use warnings;
-use Moose;
-use BAST::Web::Model::Constraint::NoMoreThan;
-use BAST::Web::Model::Constraint::OnLength;
-
-extends 'BAST::Web::Model::Constraint::NoMoreThan';
- with 'BAST::Web::Model::Constraint::OnLength';
+ package Constraint;
+ use strict;
+ use warnings;
+ use Moose;
+
+ sub validate { confess "Abstract method!" }
+ sub error_message { confess "Abstract method!" }
+
+ sub validation_value {
+ my ($self, $field) = @_;
+ return $field->value;
+ }
+
+ package Constraint::AtLeast;
+ use strict;
+ use warnings;
+ use Moose;
+
+ extends 'Constraint';
+
+ has 'value' => (isa => 'Num', is => 'ro');
+
+ sub validate {
+ my ($self, $field) = @_;
+ if ($self->validation_value($field) >= $self->value) {
+ return undef;
+ }
+ else {
+ return $self->error_message;
+ }
+ }
+
+ sub error_message { 'must be at least ' . (shift)->value; }
+
+ package Constraint::NoMoreThan;
+ use strict;
+ use warnings;
+ use Moose;
+
+ extends 'Constraint';
+
+ has 'value' => (isa => 'Num', is => 'ro');
+
+ sub validate {
+ my ($self, $field) = @_;
+ if ($self->validation_value($field) <= $self->value) {
+ return undef;
+ } else {
+ return $self->error_message;
+ }
+ }
+
+ sub error_message { 'must be no more than ' . (shift)->value; }
+
+ package Constraint::OnLength;
+ use strict;
+ use warnings;
+ use Moose::Role;
+
+ has 'units' => (isa => 'Str', is => 'ro');
+
+ override 'value' => sub {
+ return length(super());
+ };
+
+ override 'error_message' => sub {
+ my $self = shift;
+ return super() . ' ' . $self->units;
+ };
+
+ package Constraint::LengthNoMoreThan;
+ use strict;
+ use warnings;
+ use Moose;
+
+ extends 'Constraint::NoMoreThan';
+ with 'Constraint::OnLength';
+
+ package Constraint::LengthAtLeast;
+ use strict;
+ use warnings;
+ use Moose;
+
+ extends 'Constraint::AtLeast';
+ with 'Constraint::OnLength';
=cut
\ No newline at end of file