more tests
Stevan Little [Mon, 21 Jan 2008 20:43:46 +0000 (20:43 +0000)]
Changes
MANIFEST
t/020_attributes/017_attribute_traits_n_meta.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 1d97743..e4c3d03 100644 (file)
--- a/Changes
+++ b/Changes
@@ -94,6 +94,9 @@ Revision history for Perl extension Moose
         are more generic and not confined to ArrayRef
         and HashRef only
 
+    * t/
+      - shortened some file names for better VMS support (RT #32381)
+
 0.33 Fri. Dec. 14, 2007
     !! Moose now loads 2 x faster !!
     !!  with new Class::MOP 0.49  !!
index d117152..b62baa0 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -97,6 +97,7 @@ t/020_attributes/013_attr_dereference_test.t
 t/020_attributes/014_misc_attribute_coerce_lazy.t
 t/020_attributes/015_attribute_traits.t
 t/020_attributes/016_attribute_traits_registered.t
+t/020_attributes/017_attribute_traits_n_meta.t
 t/030_roles/001_meta_role.t
 t/030_roles/002_role.t
 t/030_roles/003_apply_role.t
diff --git a/t/020_attributes/017_attribute_traits_n_meta.t b/t/020_attributes/017_attribute_traits_n_meta.t
new file mode 100644 (file)
index 0000000..6930dc1
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+use Test::Exception;
+use Test::Moose;
+
+BEGIN {
+    use_ok('Moose');
+}
+
+{
+    package My::Meta::Attribute::DefaultReadOnly;
+    use Moose;
+    
+    extends 'Moose::Meta::Attribute';
+    
+    around 'new' => sub {
+        my $next = shift;
+        my ($self, $name, %options) = @_;
+        $options{is} = 'ro' 
+            unless exists $options{is};
+        $next->($self, $name, %options);
+    };    
+}
+
+{
+    package My::Attribute::Trait;
+    use Moose::Role;
+    
+    has 'alias_to' => (is => 'ro', isa => 'Str');
+    
+    after 'install_accessors' => sub {
+        my $self = shift;
+        $self->associated_class->add_method(
+            $self->alias_to, 
+            $self->get_read_method_ref
+        );
+    };
+}
+
+{
+    package My::Class;
+    use Moose;
+    
+    has 'bar' => (
+        metaclass => 'My::Meta::Attribute::DefaultReadOnly',
+        traits    => [qw/My::Attribute::Trait/],
+        isa       => 'Int',
+        alias_to  => 'baz',
+    );
+}
+
+my $c = My::Class->new(bar => 100);
+isa_ok($c, 'My::Class');
+
+is($c->bar, 100, '... got the right value for bar');
+
+can_ok($c, 'baz');
+is($c->baz, 100, '... got the right value for baz');
+
+isa_ok($c->meta->get_attribute('bar'), 'My::Meta::Attribute::DefaultReadOnly');
+does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');
+is($c->meta->get_attribute('bar')->_is_metadata, 'ro', '... got the right metaclass customization');
+
+
+
+