Add an example using NativeTraits
gfx [Mon, 15 Mar 2010 09:29:31 +0000 (18:29 +0900)]
example/traits.pl [new file with mode: 0644]

diff --git a/example/traits.pl b/example/traits.pl
new file mode 100644 (file)
index 0000000..50a74c6
--- /dev/null
@@ -0,0 +1,30 @@
+#!perl
+package IntStack;
+use Mouse;
+
+has storage => (
+    is => 'ro',
+    isa => 'ArrayRef[Int]',
+
+    default => sub{ [] },
+    traits  => [qw(Array)],
+
+    handles => {
+        push => 'push',
+        pop  => 'pop',
+        top  => [ get => -1 ],
+    },
+);
+
+__PACKAGE__->meta->make_immutable();
+
+package main;
+
+my $stack = IntStack->new;
+
+$stack->push(42);
+$stack->push(27);
+
+print $stack->pop, "\n";
+print $stack->top, "\n";
+