Provide optimize_as for pre-2.0100 Moose versions
Dagfinn Ilmari Mannsåker [Mon, 12 Dec 2011 12:49:59 +0000 (12:49 +0000)]
Changes
Makefile.PL
lib/MooseX/Types/DateTime.pm

diff --git a/Changes b/Changes
index 060096f..4e560bf 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+
+        - Provide optimize_as for pre-2.0100 Moose versions
+
 0.06
         - Use inline_as instead of the deprecated optimize_as
 
index 1e4b3a9..b047420 100644 (file)
@@ -10,7 +10,7 @@ WriteMakefile(
     INSTALLDIRS  => 'site',
     PL_FILES     => { },
     PREREQ_PM => {
-        'Moose'              => '2.0100', # inline_as
+        'Moose'              => '0.41', # class_type
         'DateTime'           => '0.4302',
         'DateTime::Locale'   => '0.4001',
         'DateTime::TimeZone' => '0.95',
index 1d92550..fb7c927 100644 (file)
@@ -30,10 +30,16 @@ subtype Locale,   as 'DateTime::Locale';
 subtype( Now,
     as Str,
     where { $_ eq 'now' },
-    Moose::Util::TypeConstraints::inline_as {
-        'no warnings "uninitialized";'.
-        '!ref(' . $_[1] . ') and '. $_[1] .' eq "now"';
-    },
+    ($Moose::VERSION >= 2.0100
+        ? Moose::Util::TypeConstraints::inline_as {
+           'no warnings "uninitialized";'.
+           '!ref(' . $_[1] . ') and '. $_[1] .' eq "now"';
+        }
+        : Moose::Util::TypeConstraints::optimize_as {
+            no warnings 'uninitialized';
+            !ref($_[0]) and $_[0] eq 'now';
+        }
+    ),
 );
 
 our %coercions = (