--- /dev/null
+
+package MooseX::AttributeHelpers::MethodProvider::Number;
+use Moose::Role;
+
+our $VERSION = '0.02';
+our $AUTHORITY = 'cpan:STEVAN';
+
+my %ops = (
+ add => '+',
+ sub => '-',
+ mul => '*',
+ div => '/',
+ mod => '%',
+);
+foreach my $method (keys %ops)
+{
+ my $s = $ops{$method};
+ __PACKAGE__->meta->alias_method($method, sub {
+ my ($attr, $reader, $writer) = @_;
+ return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $s \$_[1]) }";
+ });
+}
+
+sub abs : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) };
+}
+
+sub set : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { $writer->($_[0], $_[1]) };
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::AttributeHelpers::MethodProvider::Number
+
+=head1 DESCRIPTION
+
+This is a role which provides the method generators for
+L<MooseX::AttributeHelpers::Number>.
+
+=head1 PROVIDED METHODS
+
+It is important to note that all those methods do in place modification of the
+value stored in the attribute. All methods but 'set' are plain mathematical
+operators, as in $current_value = $current_value I<op>$argument, where I<op> is
+the operator listed next to the method name.
+
+=over 4
+
+=item B<add>: +
+
+=item B<sub>: -
+
+=item B<mul>: *
+
+=item B<div>: /
+
+=item B<mod>: %
+
+=item B<abs>: |$val|, or $val = abs($value).
+
+=item B<set>:
+
+A way to set the value instead of 'setter' or 'is => "rw"'. This method is
+provided for convenience.
+
+=back
+
+=head1 BUGS
+
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
+
+=head1 AUTHOR
+
+Paul Driver E<lt>frowith@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007-2008 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
--- /dev/null
+
+package MooseX::AttributeHelpers::Sugar;
+use Carp qw(confess);
+use Exporter qw(import);
+our @EXPORT = qw(define_attribute_helper);
+
+sub define_attribute_helper (%) {
+ my %info = @_;
+ my $class = caller();
+ my $meta = $class->meta;
+
+ $meta->add_method('helper_type', sub {$info{helper_type}});
+ $meta->add_method('default_options', sub {$info{default_options}});
+ $meta->add_method('auto_provide', sub {$info{auto_provide} || 0});
+
+ if(my $provider = $info{method_provider}) {
+ eval "require $provider";
+ confess "Error loading method provider" if $@;
+ $meta->add_attribute('+method_provider', default => $provider);
+ }
+
+ if (my $cons = $info{method_constructors}) {
+ $meta->add_attribute('+method_constructors', default => $cons)
+ }
+
+ if (my $s = $info{shortcut}) {
+ $meta->create("Moose::Meta::Attribute::Custom::$s",
+ methods => {register_implementation => sub { $class }},
+ );
+ }
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+MooseX::AttributeHelpers::Sugar - Convenience for defining AttributeHelper
+metaclasses.
+
+=head1 SYNOPSIS
+
+ package MooseX::AttributeHelpers::Counter;
+ use Moose;
+ use MooseX::AttributeHelpers::Sugar;
+
+ extends 'MooseX::AttributeHelpers::Base';
+
+ define_attribute_helper (
+ default_options => {
+ is => 'ro',
+ default => 0,
+ },
+
+ helper_type => 'Num',
+ method_provider => 'MooseX::AttributeHelpers::MethodProvider::Counter',
+ auto_provide => 1,
+ shortcut => 'Counter',
+ );
+
+ no Moose;
+ no MooseX::AttributeHelpers::Sugar;
+
+ 1;
+
+=head1 DESCRIPTION
+
+This is just sugar to let you declaratively subclass
+L<MooseX::AttributeHelpers::Base>. You still need to explicitly subclass, but
+most of the boilerplate is taken care of for you by the sugar. One function is
+exported.
+
+=over 4
+
+=item B<define_attribute_helper>
+
+The following parameters are accepted, and are used to override methods in
+the base class (see its documentation for details).
+
+=item B<default_options> I<HashRef>
+
+=item B<helper_type> I<String>
+
+=item B<auto_provide> I<Bool>
+
+=item B<method_provider> I<ClassName>
+
+=item B<method_constructors> I<HashRef>
+
+=back
+
+=head SHORTCUT
+
+For ease of use of the generated metaclasses, if you pass in a "shortcut"
+parameter to define_attribute_helper, a class at
+Moose::Meta::Attribute::Custom::$shortcut will be generated for you, which
+allows clients of your class to specify their metaclass by this shortcut
+(without the long prefix).
+
+=head1 BUGS
+
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
+
+=head1 AUTHOR
+
+Paul Driver E<lt> frodwith at cpan.org E<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007, 2008 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut