[Moose-commits] r7476 - in MooseX-Types-Common/trunk:
lib/MooseX/Types lib/MooseX/Types/Common t
groditi at code2.0beta.co.uk
groditi at code2.0beta.co.uk
Mon Feb 2 20:05:28 GMT 2009
Author: groditi
Date: 2009-02-02 12:05:27 -0800 (Mon, 02 Feb 2009)
New Revision: 7476
Added:
MooseX-Types-Common/trunk/lib/MooseX/Types/Common/
MooseX-Types-Common/trunk/lib/MooseX/Types/Common/Numeric.pm
MooseX-Types-Common/trunk/lib/MooseX/Types/Common/String.pm
MooseX-Types-Common/trunk/t/01-string.t
MooseX-Types-Common/trunk/t/02-numeric.t
Removed:
MooseX-Types-Common/trunk/t/01-common.t
Modified:
MooseX-Types-Common/trunk/lib/MooseX/Types/Common.pm
MooseX-Types-Common/trunk/t/00-load.t
Log:
restructuring
Added: MooseX-Types-Common/trunk/lib/MooseX/Types/Common/Numeric.pm
===================================================================
--- MooseX-Types-Common/trunk/lib/MooseX/Types/Common/Numeric.pm (rev 0)
+++ MooseX-Types-Common/trunk/lib/MooseX/Types/Common/Numeric.pm 2009-02-02 20:05:27 UTC (rev 7476)
@@ -0,0 +1,89 @@
+package MooseX::Types::Common::Numeric;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.001000';
+
+use MooseX::Types -declare => [
+ qw(PositiveNum PositiveInt NegativeNum NegativeInt SingleDigit)
+];
+
+use MooseX::Types::Moose qw/Num Int/;
+
+subtype PositiveNum,
+ as Num,
+ where { $_ >= 0 },
+ message { "Must be a positive number" };
+
+subtype PositiveInt,
+ as Int,
+ where { $_ >= 0 },
+ message { "Must be a positive integer" };
+
+subtype NegativeNum,
+ as Num,
+ where { $_ <= 0 },
+ message { "Must be a negative number" };
+
+subtype NegativeInt,
+ as Int,
+ where { $_ <= 0 },
+ message { "Must be a negative integer" };
+
+subtype SingleDigit,
+ as PositiveInt,
+ where { $_ <= 9 },
+ message { "Must be a single digit" };
+
+
+1;
+
+__END__;
+
+
+=head1 NAME
+
+MooseX::Types::Common::Numeric
+
+=head1 SYNOPSIS
+
+ use MooseX::Types::Common::Numeric qw/PositiveInt/;
+ has count => (is => 'rw', isa => PositiveInt);
+
+ ...
+ #this will fail
+ $object->count(-33);
+
+=head1 DESCRIPTION
+
+A set of commonly-used numeric type constraints that do not ship with Moose by
+default.
+
+=over
+
+=item * PositiveNum
+
+=item * PositiveInt
+
+=item * NegativeNum
+
+=item * Int
+
+=item * SingleDigit
+
+=back
+
+=head1 SEE ALSO
+
+=over
+
+=item * L<MooseX::Types::Common::String>
+
+=back
+
+=head1 AUTHORS
+
+Please see:: L<MooseX::Types::Common>
+
+=cut
Added: MooseX-Types-Common/trunk/lib/MooseX/Types/Common/String.pm
===================================================================
--- MooseX-Types-Common/trunk/lib/MooseX/Types/Common/String.pm (rev 0)
+++ MooseX-Types-Common/trunk/lib/MooseX/Types/Common/String.pm 2009-02-02 20:05:27 UTC (rev 7476)
@@ -0,0 +1,91 @@
+package MooseX::Types::Common::String;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.001000';
+
+use MooseX::Types -declare => [
+ qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr)
+];
+
+use MooseX::Types::Moose qw/Str/;
+
+subtype SimpleStr,
+ as Str,
+ where { (length($_) <= 255) && ($_ !~ m/\n/) },
+ message { "Must be a single line of no more than 255 chars" };
+
+subtype NonEmptySimpleStr,
+ as SimpleStr,
+ where { length($_) > 0 },
+ message { "Must be a non-empty single line of no more than 255 chars" };
+
+# XXX duplicating constraint msges since moose only uses last message
+subtype Password,
+ as NonEmptySimpleStr,
+ where { length($_) > 3 },
+ message { "Must be between 4 and 255 chars" };
+
+subtype StrongPassword,
+ as Password,
+ where { (length($_) > 7) && (m/[^a-zA-Z]/) },
+ message {"Must be between 8 and 255 chars, and contain a non-alpha char" };
+
+subtype NonEmptyStr,
+ as Str,
+ where { length($_) > 0 },
+ message { "Must not be empty" };
+
+
+1;
+
+=head1 NAME
+
+MooseX::Types::Common::String
+
+=head1 SYNOPSIS
+
+ use MooseX::Types::Common::String qw/SimpleStr/;
+ has short_str => (is => 'rw', isa => SimpleStr);
+
+ ...
+ #this will fail
+ $object->short_str("string\nwith\nbreaks");
+
+=head1 DESCRIPTION
+
+A set of commonly-used string type constraints that do not ship with Moose by
+default.
+
+=over
+
+=item * SimpleStr
+
+A Str with no new-line characters.
+
+=item * NonEmptySimpleStr
+
+Does what it says on the tin.
+
+=item * Password
+
+=item * StrongPassword
+
+=item * NonEmptyStr
+
+=back
+
+=head1 SEE ALSO
+
+=over
+
+=item * L<MooseX::Types::Common::Numeric>
+
+=back
+
+=head1 AUTHORS
+
+Please see:: L<MooseX::Types::Common>
+
+=cut
Modified: MooseX-Types-Common/trunk/lib/MooseX/Types/Common.pm
===================================================================
--- MooseX-Types-Common/trunk/lib/MooseX/Types/Common.pm 2009-02-01 23:49:24 UTC (rev 7475)
+++ MooseX-Types-Common/trunk/lib/MooseX/Types/Common.pm 2009-02-02 20:05:27 UTC (rev 7476)
@@ -5,64 +5,6 @@
our $VERSION = '0.001000';
-use MooseX::Types -declare => [
- qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr
- PositiveNum PositiveInt NegativeNum NegativeInt SingleDigit)
-];
-
-use MooseX::Types::Moose qw/Str Num Int Object/;
-
-subtype SimpleStr,
- as Str,
- where { (length($_) <= 255) && ($_ !~ m/\n/) },
- message { "Must be a single line of no more than 255 chars" };
-
-subtype NonEmptySimpleStr,
- as SimpleStr,
- where { length($_) > 0 },
- message { "Must be a non-empty single line of no more than 255 chars" };
-
-# XXX duplicating constraint msges since moose only uses last message
-subtype Password,
- as NonEmptySimpleStr,
- where { length($_) > 3 },
- message { "Must be between 4 and 255 chars" };
-
-subtype StrongPassword,
- as Password,
- where { (length($_) > 7) && (m/[^a-zA-Z]/) },
- message {"Must be between 8 and 255 chars, and contain a non-alpha char" };
-
-subtype NonEmptyStr,
- as Str,
- where { length($_) > 0 },
- message { "Must not be empty" };
-
-subtype PositiveNum,
- as Num,
- where { $_ >= 0 },
- message { "Must be a positive number" };
-
-subtype PositiveInt,
- as Int,
- where { $_ >= 0 },
- message { "Must be a positive integer" };
-
-subtype NegativeNum,
- as Num,
- where { $_ <= 0 },
- message { "Must be a negative number" };
-
-subtype NegativeInt,
- as Int,
- where { $_ <= 0 },
- message { "Must be a negative integer" };
-
-subtype SingleDigit,
- as PositiveInt,
- where { $_ <= 9 },
- message { "Must be a single digit" };
-
1;
=head1 NAME
@@ -71,49 +13,34 @@
=head1 SYNOPSIS
- use MooseX::Types::Common qw/SimpleStr/;
+ use MooseX::Types::Common::String qw/SimpleStr/;
has short_str => (is => 'rw', isa => SimpleStr);
...
#this will fail
$object->short_str("string\nwith\nbreaks");
-=head1 DESCRIPTION
-A set of commonly-used type constraints that do not ship with Moose by default.
-=over
+ use MooseX::Types::Common::Numeric qw/PositiveInt/;
+ has count => (is => 'rw', isa => PositiveInt);
-=item * SimpleStr
+ ...
+ #this will fail
+ $object->count(-33);
-A Str with no new-line characters.
+=head1 DESCRIPTION
-=item * NonEmptySimpleStr
+A set of commonly-used type constraints that do not ship with Moose by default.
-Does what it says on the tin.
-
-=item * Password
-
-=item * StrongPassword
-
-=item * NonEmptyStr
-
-=item * PositiveNum
-
-=item * PositiveInt
-
-=item * NegativeNum
-
-=item * Int
-
-=item * SingleDigit
-
-=back
-
=head1 SEE ALSO
=over
+=item * L<MooseX::Types::Common::String>
+
+=item * L<MooseX::Types::Common::Numeric>
+
=item * L<MooseX::Types>
=item * L<Moose::Util::TypeConstraints>
Modified: MooseX-Types-Common/trunk/t/00-load.t
===================================================================
--- MooseX-Types-Common/trunk/t/00-load.t 2009-02-01 23:49:24 UTC (rev 7475)
+++ MooseX-Types-Common/trunk/t/00-load.t 2009-02-02 20:05:27 UTC (rev 7476)
@@ -2,6 +2,8 @@
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More tests => 3;
use_ok('MooseX::Types::Common');
+use_ok('MooseX::Types::Common::String');
+use_ok('MooseX::Types::Common::Numeric');
Deleted: MooseX-Types-Common/trunk/t/01-common.t
===================================================================
--- MooseX-Types-Common/trunk/t/01-common.t 2009-02-01 23:49:24 UTC (rev 7475)
+++ MooseX-Types-Common/trunk/t/01-common.t 2009-02-02 20:05:27 UTC (rev 7476)
@@ -1,63 +0,0 @@
-#! /usr/bin/perl -w
-
-use strict;
-use warnings;
-use Test::More tests => 26;
-use Test::Exception;
-
-{
- package FooTest;
- use Moose;
- use MooseX::Types::Common (
- qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr),
- qw(PositiveNum PositiveInt NegativeInt NegativeNum SingleDigit)
- );
-
- has simplestr => ( is => 'rw', isa => SimpleStr);
- has nestr => ( is => 'rw', isa => NonEmptyStr);
- has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr);
- has password => ( is => 'rw', isa => Password);
- has strongpassword => ( is => 'rw', isa => StrongPassword);
-
- has digit => ( is => 'rw', isa => SingleDigit);
- has posnum => ( is => 'rw', isa => PositiveNum);
- has posint => ( is => 'rw', isa => PositiveInt);
- has negnum => ( is => 'rw', isa => NegativeNum);
- has negint => ( is => 'rw', isa => NegativeInt);
-}
-
-my $ins = FooTest->new;
-
-lives_ok { $ins->simplestr('') } 'SimpleStr';
-lives_ok { $ins->simplestr('good string') } 'SimpleStr 2';
-dies_ok { $ins->simplestr("bad\nstring") } 'SimpleStr 3';
-dies_ok { $ins->simplestr(join('', ("long string" x 25))) } 'SimpleStr 4';
-
-dies_ok { $ins->nestr('') } 'NonEmptyStr';
-lives_ok { $ins->nestr('good string') } 'NonEmptyStr 2';
-lives_ok { $ins->nestr("bad\nstring") } 'NonEmptyStr 3';
-lives_ok { $ins->nestr(join('', ("long string" x 25))) } 'NonEmptyStr 4';
-
-lives_ok { $ins->nesimplestr('good str') } 'NonEmptySimplrStr ';
-dies_ok { $ins->nesimplestr('') } 'NonEmptyStr 2';
-
-dies_ok { $ins->password('no') } 'Password';
-lives_ok { $ins->password('okay') } 'Password 2';
-
-dies_ok { $ins->strongpassword('notokay') } 'StrongPassword';
-lives_ok { $ins->strongpassword('83773r_ch01c3') } 'StrongPassword 2';
-
-dies_ok { $ins->digit(100); } 'SingleDigit';
-lives_ok { $ins->digit(1); } 'SingleDigit 2';
-
-dies_ok { $ins->posint(-100); } 'PositiveInt';
-dies_ok { $ins->posint(100.885); } 'PositiveInt 2';
-lives_ok { $ins->posint(100); } 'PositiveInt 3';
-lives_ok { $ins->posnum(100.885); } 'PositiveNum';
-dies_ok { $ins->posnum(-100.885); } 'PositiveNum 2';
-
-dies_ok { $ins->negint(100); } 'NegativeInt';
-dies_ok { $ins->negint(-100.885); } 'NegativeInt 2';
-lives_ok { $ins->negint(-100); } 'NegativeInt 3';
-lives_ok { $ins->negnum(-100.885); } 'NegativeNum';
-dies_ok { $ins->negnum(100.885); } 'NegativeNum 2';
Added: MooseX-Types-Common/trunk/t/01-string.t
===================================================================
--- MooseX-Types-Common/trunk/t/01-string.t (rev 0)
+++ MooseX-Types-Common/trunk/t/01-string.t 2009-02-02 20:05:27 UTC (rev 7476)
@@ -0,0 +1,41 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 14;
+use Test::Exception;
+
+{
+ package FooTest;
+ use Moose;
+ use MooseX::Types::Common (
+ qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr),
+ );
+
+ has simplestr => ( is => 'rw', isa => SimpleStr);
+ has nestr => ( is => 'rw', isa => NonEmptyStr);
+ has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr);
+ has password => ( is => 'rw', isa => Password);
+ has strongpassword => ( is => 'rw', isa => StrongPassword);
+}
+
+my $ins = FooTest->new;
+
+lives_ok { $ins->simplestr('') } 'SimpleStr';
+lives_ok { $ins->simplestr('good string') } 'SimpleStr 2';
+dies_ok { $ins->simplestr("bad\nstring") } 'SimpleStr 3';
+dies_ok { $ins->simplestr(join('', ("long string" x 25))) } 'SimpleStr 4';
+
+dies_ok { $ins->nestr('') } 'NonEmptyStr';
+lives_ok { $ins->nestr('good string') } 'NonEmptyStr 2';
+lives_ok { $ins->nestr("bad\nstring") } 'NonEmptyStr 3';
+lives_ok { $ins->nestr(join('', ("long string" x 25))) } 'NonEmptyStr 4';
+
+lives_ok { $ins->nesimplestr('good str') } 'NonEmptySimplrStr ';
+dies_ok { $ins->nesimplestr('') } 'NonEmptyStr 2';
+
+dies_ok { $ins->password('no') } 'Password';
+lives_ok { $ins->password('okay') } 'Password 2';
+
+dies_ok { $ins->strongpassword('notokay') } 'StrongPassword';
+lives_ok { $ins->strongpassword('83773r_ch01c3') } 'StrongPassword 2';
Added: MooseX-Types-Common/trunk/t/02-numeric.t
===================================================================
--- MooseX-Types-Common/trunk/t/02-numeric.t (rev 0)
+++ MooseX-Types-Common/trunk/t/02-numeric.t 2009-02-02 20:05:27 UTC (rev 7476)
@@ -0,0 +1,37 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 12;
+use Test::Exception;
+
+{
+ package FooTest;
+ use Moose;
+ use MooseX::Types::Common (
+ qw(PositiveNum PositiveInt NegativeInt NegativeNum SingleDigit)
+ );
+
+ has digit => ( is => 'rw', isa => SingleDigit);
+ has posnum => ( is => 'rw', isa => PositiveNum);
+ has posint => ( is => 'rw', isa => PositiveInt);
+ has negnum => ( is => 'rw', isa => NegativeNum);
+ has negint => ( is => 'rw', isa => NegativeInt);
+}
+
+my $ins = FooTest->new;
+
+dies_ok { $ins->digit(100); } 'SingleDigit';
+lives_ok { $ins->digit(1); } 'SingleDigit 2';
+
+dies_ok { $ins->posint(-100); } 'PositiveInt';
+dies_ok { $ins->posint(100.885); } 'PositiveInt 2';
+lives_ok { $ins->posint(100); } 'PositiveInt 3';
+lives_ok { $ins->posnum(100.885); } 'PositiveNum';
+dies_ok { $ins->posnum(-100.885); } 'PositiveNum 2';
+
+dies_ok { $ins->negint(100); } 'NegativeInt';
+dies_ok { $ins->negint(-100.885); } 'NegativeInt 2';
+lives_ok { $ins->negint(-100); } 'NegativeInt 3';
+lives_ok { $ins->negnum(-100.885); } 'NegativeNum';
+dies_ok { $ins->negnum(100.885); } 'NegativeNum 2';
More information about the Moose-commits
mailing list