File: inc2.pl

package info (click to toggle)
libmousex-nativetraits-perl 1.09-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 480 kB
  • sloc: perl: 5,073; makefile: 7
file content (59 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (4)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!perl -w

use strict;
use Benchmark qw(:all);

print "Benchmark for native traits (Counter)\n";

{
    package MouseCounter;
    use Mouse;

    has ok => (
        is  => 'rw',
        isa => 'Int',

        traits => ['Counter'],

        handles => {
            inc2 => [inc => 2 ],
        },
        default => 0,
        clearer => 'foo',
    );

    __PACKAGE__->meta->make_immutable();
}

{
    package MooseCounter;
    use Moose;

    has ok => (
        is  => 'rw',
        isa => 'Int',

        traits => ['Counter'],

        handles => {
            inc2 => [inc => 2 ],
        },
        default => 0,
    );

    __PACKAGE__->meta->make_immutable();
}

print "curried inc\n";
cmpthese -1 => {
    Mouse => sub{
        my $mouse = MouseCounter->new;
        $mouse->inc2() for 1 .. 100;
        $mouse->ok == 200 or die $mouse->ok;
    },
    Moose => sub{
        my $moose = MooseCounter->new;
        $moose->inc2() for 1 .. 100;
        $moose->ok == 200 or die $moose->ok;
    },
};