• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Data/H03-May-2022-21346

t/H27-Mar-2010-887615

ChangesH A D27-Mar-20101.8 KiB4635

INSTALLH A D27-Mar-2010515 2815

LICENSEH A D27-Mar-201017.8 KiB378292

MANIFESTH A D27-Mar-2010507 2929

MANIFEST.SKIPH A D27-Mar-2010476 4339

META.jsonH A D27-Mar-20101.1 KiB4442

META.ymlH A D27-Mar-2010825 3534

Makefile.PLH A D27-Mar-20101.7 KiB4835

READMEH A D27-Mar-20104.2 KiB143106

dist.iniH A D27-Mar-2010156 86

README

1NAME
2    Data::Inherited - Hierarchy-wide accumulation of list and hash results
3
4VERSION
5    version 1.100860
6
7SYNOPSIS
8      package Foo;
9      use base 'Data::Inherited';
10      use constant PROPERTIES => (qw/name address/);
11
12      package Bar;
13      use base 'Foo';
14      use constant PROPERTIES => (qw/age/);
15
16      package main;
17      my $bar = Bar->new;
18      print "$_\n" for $bar->every_list('PROPERTIES');
19
20      # prints:
21      #
22      # name
23      # address
24      # age
25
26DESCRIPTION
27    This is a mixin class. By inheriting from it you get two methods that
28    are able to accumulate hierarchy-wide list and hash results.
29
30METHODS
31  every_list(String $method_name, Bool ?$override_cache = 0)
32    Takes as arguments a method name (mandatory) and a boolean indicating
33    whether to override the cache (optional, off by default)
34
35    Causes every method in the object's hierarchy with the given name to be
36    invoked. The resulting list is the combined set of results from all the
37    methods, pushed together in top-to-bottom order (hierarchy-wise).
38
39    "every_list()" returns a list in list context and an array reference in
40    scalar context.
41
42    The result is cached (per calling package) and the next time the method
43    is called from the same package with the same method argument, the
44    cached result is returned. This is to speed up method calls, because
45    internally this module uses NEXT, which is quite slow. It is expected
46    that "every_list()" is used for methods returning static lists (object
47    defaults, static class definitions and such). If you want to override
48    the caching mechanism, you can provide the optional second argument. The
49    result is cached in any case.
50
51    See the synopsis for an example.
52
53  every_hash(String $method_name, Bool ?$override_cache = 0)
54    Takes as arguments a method name (mandatory) and a boolean indicating
55    whether to override the cache (optional, off by default)
56
57    Causes every method in the object's hierarchy with the given name to be
58    invoked. The resulting hash is the combined set of results from all the
59    methods, overlaid in top-to-bottom order (hierarchy-wise).
60
61    "every_hash()" returns a hash in list context and a hash reference in
62    scalar context.
63
64    The cache and the optional cache override argument work like with
65    "every_list()".
66
67    Example:
68
69      package Person;
70      use base 'Data::Inherited';
71
72      sub new {
73        my $class = shift;
74        my $self = bless {}, $class;
75        my %args = @_;
76        %args = ($self->every_hash('DEFAULTS'), %args);
77        $self->$_($args{$_}) for keys %args;
78        $self;
79      };
80
81      sub DEFAULTS {
82        first_name => 'John',
83        last_name  => 'Smith',
84      };
85
86      package Employee;
87      use base 'Person';
88
89      sub DEFAULTS {
90        salary => 10_000,
91      }
92
93      package LocatedEmployee;
94      use base 'Employee';
95
96      # Note: no default for address, but different salary
97
98      sub DEFAULTS {
99        salary     => 20_000,
100        first_name => 'Johan',
101      }
102
103      package main;
104      my $p = LocatedEmployee->new;
105
106      # salary: 20000
107      # first_name: Johan
108      # last_name: Smith
109
110  flush_every_cache_by_key(String $key)
111    Deletes the cache entry for the given key.
112
113INSTALLATION
114    See perlmodinstall for information and options on installing Perl
115    modules.
116
117BUGS AND LIMITATIONS
118    No bugs have been reported.
119
120    Please report any bugs or feature requests through the web interface at
121    <http://rt.cpan.org/Public/Dist/Display.html?Name=Data-Inherited>.
122
123AVAILABILITY
124    The latest version of this module is available from the Comprehensive
125    Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a
126    CPAN site near you, or see
127    <http://search.cpan.org/dist/Data-Inherited/>.
128
129    The development version lives at
130    <http://github.com/hanekomu/Data-Inherited/>. Instead of sending
131    patches, please fork this project using the standard git and github
132    infrastructure.
133
134AUTHOR
135      Marcel Gruenauer <marcel@cpan.org>
136
137COPYRIGHT AND LICENSE
138    This software is copyright (c) 2004 by Marcel Gruenauer.
139
140    This is free software; you can redistribute it and/or modify it under
141    the same terms as the Perl 5 programming language system itself.
142
143