From: gfx Date: Mon, 15 Mar 2010 09:29:31 +0000 (+0900) Subject: Add an example using NativeTraits X-Git-Tag: 0.52~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a41b51bdf840218091b09c3216d2bc3cc337b0ba;p=gitmo%2FMouse.git Add an example using NativeTraits --- diff --git a/example/traits.pl b/example/traits.pl new file mode 100644 index 0000000..50a74c6 --- /dev/null +++ b/example/traits.pl @@ -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"; +