Commit | Line | Data |
0ab65f99 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Scalar::Util 'blessed', 'reftype'; |
7 | |
8 | use Test::More tests => 4; |
9 | |
10 | BEGIN { |
11 | use_ok('Class::MOP'); |
12 | } |
13 | |
14 | =pod |
15 | |
16 | This checks that the initializer is used to set the initial value. |
17 | |
18 | =cut |
19 | |
20 | { |
21 | package Foo; |
22 | use metaclass; |
23 | |
24 | Foo->meta->add_attribute('bar' => |
25 | reader => 'get_bar', |
26 | writer => 'set_bar', |
27 | initializer => sub { |
c0921932 |
28 | my ($self, $value, $callback, $attr) = @_; |
0ab65f99 |
29 | $callback->($value * 2); |
30 | }, |
31 | ); |
32 | } |
33 | |
34 | can_ok('Foo', 'get_bar'); |
35 | can_ok('Foo', 'set_bar'); |
36 | |
37 | my $foo = Foo->meta->construct_instance(bar => 10); |
38 | is( |
39 | $foo->get_bar, |
40 | 20, |
41 | "initial argument was doubled as expected", |
42 | ); |
43 | |