Browse files

Merge pull request #3 from shadowcat-mst/master

Add support for Moo type inflation to Moose, switch to Distar
  • Loading branch information...
2 parents fd9ad26 + 8d88e24 commit 6b8dbfef56299bc611ecbf81cde99042f2f534a4 @mateu committed Apr 7, 2012
Showing with 63 additions and 23 deletions.
  1. +13 −0 Makefile.PL
  2. +0 −15 dist.ini
  3. +40 −7 lib/MooX/Types/MooseLike.pm
  4. +3 −1 lib/MooX/Types/MooseLike/Numeric.pm
  5. +7 −0 maint/Makefile.PL.include
View
13 Makefile.PL
@@ -0,0 +1,13 @@
+use strict;
+use warnings FATAL => 'all';
+use 5.008001;
+use ExtUtils::MakeMaker;
+(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
+
+WriteMakefile(
+ NAME => 'MooX-Types-MooseLike',
+ VERSION_FROM => 'lib/MooX/Types/MooseLike.pm',
+ PREREQ_PM => {
+ Moo => '0.009015',
+ }
+);
View
15 dist.ini
@@ -1,15 +0,0 @@
-name = MooX-Types-MooseLike
-abstract = Moose Like Types for Moo
-
-[AutoPrereqs]
-[@Basic]
-
-[Git::NextVersion]
-[PkgVersion]
-[NextRelease]
-
-[@Git]
-
-[@TestingMania]
-disable = Test::Kwalitee, EOLTests, PodCoverageTests, Test::DistManifest
-
View
47 lib/MooX/Types/MooseLike.pm
@@ -1,11 +1,15 @@
-use strictures 1;
package MooX::Types::MooseLike;
+
+use strictures 1;
use Exporter 5.57 'import';
+use Module::Runtime qw(require_module);
+
+our $VERSION = '0.04';
sub register_types {
- my ($type_definitions, $into) = @_;
+ my ($type_definitions, $into, $moose_namespace) = @_;
foreach my $type_def (@{$type_definitions}) {
- my $coderefs = make_type($type_def);
+ my $coderefs = make_type($type_def, $moose_namespace);
install_type($type_def->{name}, $coderefs, $into);
}
}
@@ -26,7 +30,7 @@ sub install_type {
}
sub make_type {
- my ($type_definition) = @_;
+ my ($type_definition, $moose_namespace) = @_;
my $test = $type_definition->{test};
my $full_test = $test;
@@ -38,10 +42,21 @@ sub make_type {
$full_test = sub {return (&{$subtype_test}(@_) && $test->(@_)); };
}
+ my $isa = sub {
+ die $type_definition->{message}->(@_) if not $full_test->(@_);
+ };
+
+ my $full_name = $moose_namespace
+ ? "${moose_namespace}::".$type_definition->{name}
+ : $type_definition->{name};
+
+ $Moo::HandleMoose::TYPE_MAP{$isa} = sub {
+ require_module($moose_namespace) if $moose_namespace;
+ Moose::Util::TypeConstraints::find_type_constraint($full_name);
+ };
+
return {
- type => sub {
- sub { die $type_definition->{message}->(@_) if not $full_test->(@_); };
- },
+ type => sub { $isa },
is_type => sub { $test->($_[0]) },
};
}
@@ -77,4 +92,22 @@ See L<MooX::Types::MooseLike::Base> for an example of how to build base types.
See L<MooX::Types::MooseLike::Numeric> for an example of how to build subtypes.
+=head1 AUTHOR
+
+mateu - Mateu X. Hunter (cpan:MATEU) <hunter@missoula.org>
+
+=head1 CONTRIBUTORS
+
+mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
+
+=head1 COPYRIGHT
+
+Copyright (c) 2011-2012 the MooX::Types::MooseLike L</AUTHOR> and
+ L</CONTRIBUTORS> as listed above.
+
+=head1 LICENSE
+
+This library is free software and may be distributed under the same terms
+as perl itself.
+=cut
View
4 lib/MooX/Types/MooseLike/Numeric.pm
@@ -71,7 +71,9 @@ my $type_definitions = [
},
];
-MooX::Types::MooseLike::register_types($type_definitions, __PACKAGE__);
+MooX::Types::MooseLike::register_types(
+ $type_definitions, __PACKAGE__, 'MooseX::Types::Common::Numeric'
+);
our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
1
View
7 maint/Makefile.PL.include
@@ -0,0 +1,7 @@
+BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") }
+use lib 'Distar/lib';
+use Distar;
+
+author 'mateu - Mateu X. Hunter (cpan:MATEU) <hunter@missoula.org>';
+
+1;

0 comments on commit 6b8dbfe

Please sign in to comment.