adding in the new junk to this
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Array.pm
index 5336366..07c341b 100644 (file)
@@ -1,7 +1,7 @@
 package MooseX::AttributeHelpers::MethodProvider::Array;
 use Moose::Role;
 
-our $VERSION   = '0.03';
+our $VERSION   = '0.05';
 our $AUTHORITY = 'cpan:STEVAN';
 
 with 'MooseX::AttributeHelpers::MethodProvider::List';
@@ -9,8 +9,8 @@ with 'MooseX::AttributeHelpers::MethodProvider::List';
 sub push : method {
     my ($attr, $reader, $writer) = @_;
     
-    if ($attr->has_container_type) {
-        my $container_type_constraint = $attr->container_type_constraint;
+    if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
+        my $container_type_constraint = $attr->type_constraint->type_parameter;
         return sub { 
             my $instance = CORE::shift;
             $container_type_constraint->check($_) 
@@ -36,8 +36,8 @@ sub pop : method {
 
 sub unshift : method {
     my ($attr, $reader, $writer) = @_;
-    if ($attr->has_container_type) {
-        my $container_type_constraint = $attr->container_type_constraint;
+    if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
+        my $container_type_constraint = $attr->type_constraint->type_parameter;
         return sub { 
             my $instance = CORE::shift;
             $container_type_constraint->check($_) 
@@ -70,8 +70,8 @@ sub get : method {
 
 sub set : method {
     my ($attr, $reader, $writer) = @_;
-    if ($attr->has_container_type) {
-        my $container_type_constraint = $attr->container_type_constraint;
+    if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
+        my $container_type_constraint = $attr->type_constraint->type_parameter;
         return sub { 
             ($container_type_constraint->check($_[2])) 
                 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
@@ -101,17 +101,17 @@ sub delete : method {
 
 sub insert : method {
     my ($attr, $reader, $writer) = @_;
-    if ($attr->has_container_type) {
-        my $container_type_constraint = $attr->container_type_constraint;
+    if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
+        my $container_type_constraint = $attr->type_constraint->type_parameter;
         return sub { 
             ($container_type_constraint->check($_[2])) 
                 || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
-            splice @{$reader->($_[0])}, $_[1], 0, $_[2];
+            CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
         };                    
     }
     else {                
         return sub { 
-            splice @{$reader->($_[0])}, $_[1], 0, $_[2];
+            CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
         };
     }    
 }