* added typed-ness to collections
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Counter.pm
index 8851056..0ab0d71 100644 (file)
@@ -1,13 +1,14 @@
 
 package MooseX::AttributeHelpers::Counter;
 use Moose;
-use Moose::Util::TypeConstraints;
 
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
 extends 'MooseX::AttributeHelpers::Base';
 
+sub helper_type { 'Num' }
+
 has '+method_constructors' => (
     default => sub {
         return +{
@@ -22,24 +23,8 @@ has '+method_constructors' => (
         }
     }
 );
-
-sub _process_options_for_provides {
-    my ($self, $options) = @_;
-    (exists $options->{isa})
-        || confess "You must define a type with the Counter metaclass";  
-     
-    my $isa = $options->{isa}; 
-    
-    unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) {
-        $isa = find_type_constraint($isa);        
-    }
-    
-    ($isa->is_a_type_of('Num'))
-        || confess "The type constraint for a Counter ($options->{isa}) must be a subtype of Num";
-}
     
 no Moose;
-no Moose::Util::TypeConstraints;
 
 # register the alias ...
 package Moose::Meta::Attribute::Custom::Counter;
@@ -67,11 +52,13 @@ MooseX::AttributeHelpers::Counter
       default   => sub { 0 },
       provides  => {
           inc => 'inc_counter',
+          dec => 'dec_counter',          
       }
   );
 
   my $page = MyHomePage->new();
   $page->inc_counter; # same as $page->counter($page->counter + 1);
+  $page->dec_counter; # same as $page->counter($page->counter - 1);  
   
 =head1 DESCRIPTION