File: traits.pl

package info (click to toggle)
libmouse-perl 2.5.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,160 kB
  • sloc: perl: 14,614; ansic: 218; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 429 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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";