1Mo::build(3) User Contributed Perl Documentation Mo::build(3)
2
3
4
6 Mo::build - Adds the build feature to Mo
7
9 use Mo qw'build';
10 has name => ( is => 'rw' );
11
12 sub BUILD {
13 my $self = shift;
14 ...
15 }
16
18 Adds the "BUILD" feature to Mo when imported.
19
20 If a sub called "BUILD" exists on the package, it will be executed on
21 $self during instantiation.
22
23 Any non-lazy "default" and "builder" attributes, as well as any value
24 passed to "new" will already be set when "BUILD" is called.
25
26 package ABCD;
27 use Mo qw'build builder default';
28 use feature 'say';
29
30 has a => (default => 1234, lazy => 0);
31 has b => (builder => '_b', lazy => 0);
32 has c => (is => 'rw');
33 has d => (is => 'rw');
34
35 sub _b { 'blue' }
36
37 sub BUILD {
38 my ($self) = @_;
39 say $self->{a};
40 say $self->{b};
41 say $self->{c};
42 say 'undef' unless defined $self->{d};
43 }
44
45 ABCD->new(c => 'days') # => 1234
46 # blue
47 # days
48 # undef
49
50
51
52perl v5.30.1 2020-01-30 Mo::build(3)