--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 11;
+use Test::Exception;
+use Moose::Meta::Class;
+
+BEGIN {
+ use_ok('MooseX::AttributeHelpers');
+}
+
+my $test_index = 0;
+my %defaults = (
+ is => 'ro',
+ isa => 'Int',
+ default => 0,
+ provides => {
+ Counter => {
+ inc => 'inc_foo',
+ reset => 'reset_foo',
+ },
+ Number => {
+ mul => 'mul_foo',
+ },
+ },
+);
+sub make_test_class {
+ ++$test_index;
+ my %overrides = @_;
+ my $options = {%defaults};
+ while (my ($k,$v) = each(%overrides)) {
+ $options->{$k} = $v;
+ }
+ my $classname = "MooseX::AttributeHelpers::Test::$test_index";
+
+ my $meta = Moose::Meta::Class->create($classname,
+ superclasses => ['Moose::Object'],
+ );
+ $meta->add_attribute(foo => $options);
+ return $classname;
+}
+sub trait { traits => ['MooseX::AttributeHelpers::Composite::Trait'] }
+sub metaclass { metaclass => 'Composite' }
+
+sub simple_test {
+ my $class = make_test_class(@_);
+ my $foo = $class->new;
+ $foo->inc_foo;
+ $foo->inc_foo;
+ $foo->mul_foo(3);
+ is($foo->foo, 6, "math is correct");
+ return $foo->foo;
+}
+
+lives_ok {
+ simple_test(metaclass());
+} '... works with metaclass';
+
+lives_ok {
+ simple_test(trait());
+} '... works with trait';
+
+dies_ok {
+ simple_test(metaclass(), isa => 'Num');
+} 'dies without proper subtype';
+
+my $class = make_test_class(trait());
+
+#check meta
+
+is_deeply($class->meta->get_attribute('foo')->{provides}, {
+ Counter => {
+ inc => 'inc_foo',
+ reset => 'reset_foo',
+ },
+ Number => {
+ mul => 'mul_foo',
+ },
+}, 'provides is correct');
+
+ok($class->can('inc_foo'), 'can increment');
+ok($class->can('reset_foo'), 'can reset');
+ok($class->can('mul_foo'), 'can multiply');
+ok(!$class->can('div_foo'), 'cannot do anything else');