From: Shawn M Moore Date: Sun, 25 May 2008 01:44:31 +0000 (+0000) Subject: Simplify MooseX::AttributeHelpers::Number by just using the Number trait X-Git-Tag: 0.18_01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=393f5679e0290b61af8f8626e393f82b39492566;p=gitmo%2FMooseX-AttributeHelpers.git Simplify MooseX::AttributeHelpers::Number by just using the Number trait --- diff --git a/lib/MooseX/AttributeHelpers/Number.pm b/lib/MooseX/AttributeHelpers/Number.pm index 33bc393..5dc3674 100644 --- a/lib/MooseX/AttributeHelpers/Number.pm +++ b/lib/MooseX/AttributeHelpers/Number.pm @@ -4,51 +4,9 @@ use Moose; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -extends 'MooseX::AttributeHelpers::Base'; - -sub helper_type { 'Num' } - -# NOTE: -# we don't use the method provider for this -# module since many of the names of the provied -# methods would conflict with keywords -# - SL - -has '+method_constructors' => ( - default => sub { - return +{ - set => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $_[1]) }; - }, - add => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) }; - }, - sub => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) }; - }, - mul => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) }; - }, - div => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) }; - }, - mod => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) }; - }, - abs => sub { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], abs($reader->($_[0])) ) }; - }, - } - } -); - +extends 'Moose::Meta::Attribute'; +with 'MooseX::AttributeHelpers::Trait::Number'; + no Moose; # register the alias ...