From: Stevan Little Date: Thu, 30 Mar 2006 16:52:11 +0000 (+0000) Subject: edtis X-Git-Tag: 0_05~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3824830b46f17831fc0fc7d3a1d6099dd79d0fc1;p=gitmo%2FMoose.git edtis --- diff --git a/lib/Moose/Cookbook.pod b/lib/Moose/Cookbook.pod index 4242967..97a6338 100644 --- a/lib/Moose/Cookbook.pod +++ b/lib/Moose/Cookbook.pod @@ -16,15 +16,15 @@ details of the code. =over 4 -=item L +=item L - The (always classic) B example -=item L +=item L - A simple B example -=item L +=item L - A lazy B example -=item L +=item L - Subtypes, and modeling a simple B class hierarchy -=item L +=item L - More subtypes, coercion in a B class =back diff --git a/lib/Moose/Cookbook/Recipe1.pod b/lib/Moose/Cookbook/Recipe1.pod index 3156eec..07be5cc 100644 --- a/lib/Moose/Cookbook/Recipe1.pod +++ b/lib/Moose/Cookbook/Recipe1.pod @@ -3,7 +3,7 @@ =head1 NAME -Moose::Cookbook::Recipe1 - The (always classic) cartesian point example. +Moose::Cookbook::Recipe1 - The (always classic) B example. =head1 SYNOPSIS diff --git a/lib/Moose/Cookbook/Recipe2.pod b/lib/Moose/Cookbook/Recipe2.pod index 1272275..3039604 100644 --- a/lib/Moose/Cookbook/Recipe2.pod +++ b/lib/Moose/Cookbook/Recipe2.pod @@ -3,7 +3,7 @@ =head1 NAME -Moose::Cookbook::Recipe2 - A simple Bank Account example +Moose::Cookbook::Recipe2 - A simple B example =head1 SYNOPSIS diff --git a/lib/Moose/Cookbook/Recipe3.pod b/lib/Moose/Cookbook/Recipe3.pod index d2bfcad..97d1a9d 100644 --- a/lib/Moose/Cookbook/Recipe3.pod +++ b/lib/Moose/Cookbook/Recipe3.pod @@ -3,7 +3,7 @@ =head1 NAME -Moose::Cookbook::Recipe3 - A binary tree +Moose::Cookbook::Recipe3 - A lazy B example =head1 SYNOPSIS diff --git a/lib/Moose/Cookbook/Recipe4.pod b/lib/Moose/Cookbook/Recipe4.pod index c2a4701..36e1e92 100644 --- a/lib/Moose/Cookbook/Recipe4.pod +++ b/lib/Moose/Cookbook/Recipe4.pod @@ -3,7 +3,7 @@ =head1 NAME -Moose::Cookbook::Recipe4 - Modeling a simple B class +Moose::Cookbook::Recipe4 - Subtypes, and modeling a simple B class hierarchy =head1 SYNOPSIS diff --git a/lib/Moose/Cookbook/Recipe5.pod b/lib/Moose/Cookbook/Recipe5.pod index bcace64..e213175 100644 --- a/lib/Moose/Cookbook/Recipe5.pod +++ b/lib/Moose/Cookbook/Recipe5.pod @@ -3,7 +3,7 @@ =head1 NAME -Moose::Cookbook::Recipe5 +Moose::Cookbook::Recipe5 - More subtypes, coercion in a B class =head1 SYNOPSIS @@ -53,6 +53,8 @@ Moose::Cookbook::Recipe5 =head1 DESCRIPTION +Coming Soon. + =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/t/006_basic.t b/t/006_basic.t index 3cb0515..7cedee0 100644 --- a/t/006_basic.t +++ b/t/006_basic.t @@ -12,85 +12,90 @@ BEGIN { =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