File: constructor.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 (52 lines) | stat: -rw-r--r-- 1,292 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!perl

### MODULES


{
    package PlainMoose;
    use Moose;
    has foo => (is => 'rw');
    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable();
}
{
    package PlainMooseSC;
    use Moose;
    use MooseX::StrictConstructor;
    has foo => (is => 'rw');
    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable();
}
{
    package PlainMouse;
    use Mouse;
    has foo => (is => 'rw');
    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable();
}
{
    package PlainMouseSC;
    use Mouse;
    has foo => (is => 'rw');
    has bar => (is => 'rw');
    __PACKAGE__->meta->make_immutable(strict_constructor => 1);
}
{
    package CAF;
    use warnings;
    use strict;
    use base 'Class::Accessor::Fast';
    __PACKAGE__->mk_accessors(qw(foo bar));
}

use Benchmark qw(cmpthese);

print "\nCREATION AND DESTRUCTION\n";
cmpthese(-1, {
    Moose               => sub { my $x = PlainMoose->new(foo => 23, bar => 42) },
    Mouse               => sub { my $x = PlainMouse->new(foo => 23, bar => 42) },
    MooseSC             => sub { my $x = PlainMooseSC->new(foo => 23, bar => 42) },
    MouseSC             => sub { my $x = PlainMouseSC->new(foo => 23, bar => 42) },
    ClassAccessorFast   => sub { my $x = CAF->new({foo => 23, bar => 42}) },
}, 'noc');