1parent(3)             User Contributed Perl Documentation            parent(3)
2
3
4

NAME

6       parent - Establish an ISA relationship with base classes at compile
7       time
8

SYNOPSIS

10           package Baz;
11           use parent qw(Foo Bar);
12

DESCRIPTION

14       Allows you to both load one or more modules, while setting up
15       inheritance from those modules at the same time.  Mostly similar in
16       effect to
17
18           package Baz;
19           BEGIN {
20               require Foo;
21               require Bar;
22               push @ISA, qw(Foo Bar);
23           }
24
25       By default, every base class needs to live in a file of its own.  If
26       you want to have a subclass and its parent class in the same file, you
27       can tell "parent" not to load any modules by using the "-norequire"
28       switch:
29
30         package Foo;
31         sub exclaim { "I CAN HAS PERL" }
32
33         package DoesNotLoadFooBar;
34         use parent -norequire, 'Foo', 'Bar';
35         # will not go looking for Foo.pm or Bar.pm
36
37       This is equivalent to the following code:
38
39         package Foo;
40         sub exclaim { "I CAN HAS PERL" }
41
42         package DoesNotLoadFooBar;
43         push @DoesNotLoadFooBar::ISA, 'Foo', 'Bar';
44
45       This is also helpful for the case where a package lives within a
46       differently named file:
47
48         package MyHash;
49         use Tie::Hash;
50         use parent -norequire, 'Tie::StdHash';
51
52       This is equivalent to the following code:
53
54         package MyHash;
55         require Tie::Hash;
56         push @ISA, 'Tie::StdHash';
57
58       If you want to load a subclass from a file that "require" would not
59       consider an eligible filename (that is, it does not end in either ".pm"
60       or ".pmc"), use the following code:
61
62         package MySecondPlugin;
63         require './plugins/custom.plugin'; # contains Plugin::Custom
64         use parent -norequire, 'Plugin::Custom';
65

DIAGNOSTICS

67       Class 'Foo' tried to inherit from itself
68           Attempting to inherit from yourself generates a warning.
69
70               package Foo;
71               use parent 'Foo';
72

HISTORY

74       This module was forked from base to remove the cruft that had
75       accumulated in it.
76

CAVEATS

SEE ALSO

79       base
80

AUTHORS AND CONTRIBUTORS

82       Rafaeel Garcia-Suarez, Bart Lateur, Max Maischein, Anno Siegel, Michael
83       Schwern
84

MAINTAINER

86       Max Maischein " corion@cpan.org "
87
88       Copyright (c) 2007-10 Max Maischein "<corion@cpan.org>" Based on the
89       idea of "base.pm", which was introduced with Perl 5.004_04.
90

LICENSE

92       This module is released under the same terms as Perl itself.
93
94
95
96perl v5.16.3                      2011-03-08                         parent(3)
Impressum