1MakeMethods::Emulator::UascecresCsoonrtsr(i3b)uted PerlMDaokceuMmeetnhtoadtsi:o:nEmulator::accessors(3)
2
3
4
6 Class::MakeMethods::Emulator::accessors - Emulate the accessors module
7
9 package Foo;
10 use Class::MakeMethods::Emulator::accessors qw( foo bar baz );
11
12 my $obj = bless {}, 'Foo';
13
14 # generates chaining accessors:
15 $obj->foo( 'hello ' )
16 ->bar( 'world' )
17 ->baz( "!\n" );
18
19 print $obj->foo, $obj->bar, $obj->baz;
20
21 This module also defines subpackages for the classic and chaining
22 subclasses:
23
24 package Bar;
25 use Class::MakeMethods::Emulator::accessors;
26 use Class::MakeMethods::Emulator::accessors::classic qw( foo bar baz );
27
28 my $obj = bless {}, 'Bar';
29
30 # always return the current value, even on set:
31 $obj->foo( 'hello ' ) if $obj->bar( 'world' );
32
33 print $obj->foo, $obj->bar, $obj->baz( "!\n" );
34
36 This module emulates the functionality of the accessors module, using
37 Class::MakeMethods to generate similar methods.
38
39 In particular, the following lines are equivalent:
40
41 use accessors 'foo';
42 use Class::MakeMethods::Template::Hash 'scalar --get_set_chain' => 'foo';
43
44 use accessors::chained 'foo';
45 use Class::MakeMethods::Template::Hash 'scalar --get_set_chain' => 'foo';
46
47 use accessors::classic 'foo';
48 use Class::MakeMethods::Template::Hash 'scalar' => 'foo';
49
50 You may use this module directly, as shown in the SYNOPSIS above,
51
52 Furthermore, you may call "use Class::MakeMethods::Emulator::accessors
53 '-take_namespace';" to alias the accessors namespace to this package,
54 and subsequent calls to the original package will be transparently
55 handled by this emulator. To remove the emulation aliasing, call "use
56 Class::MakeMethods::Emulator::accessors '-release_namespace'". The
57 same mechanism is also available for the classic and chained
58 subclasses.
59
60 Caution: This affects all subsequent uses of the accessors module in
61 your program, including those in other modules, and might cause
62 unexpected effects.
63
65 See Class::MakeMethods for general information about this distribution.
66
67 See Class::MakeMethods::Emulator for more about this family of
68 subclasses.
69
70 See accessors for documentation of the original module.
71
72
73
74perl v5.30.0 2019-07-26MakeMethods::Emulator::accessors(3)