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

NAME

6       Hash::WithDefaults - class for hashes with key-casing requirements
7       supporting defaults
8
9       version 0.04
10

SYNOPSIS

12         use Hash::WithDefaults;
13
14         %main = ( ... );
15         tie %h1, 'Hash::WithDefaults', {...};
16         tied(%h1)->AddDefault(\%main);
17         tie %h2, 'Hash::WithDefaults', {...};
18         tied(%h2)->AddDefault(\%main);
19
20         # now if you use $h1{$key}, the value is looked up first
21         # in %h1, then in %main.
22

DESCRIPTION

24       This module implements hashes that support "defaults". That is you may
25       specify several more hashes in which the data will be looked up in case
26       it is not found in the current hash.
27
28   Object creation
29               tie %hash, 'Hash::WithDefault', [$case_option], [\%values];
30               tie %hash, 'Hash::WithDefault', [$case_option], [%values];
31
32       The optional $case_option may be one of these values:
33
34         Sensitive     - the hash will be case sensitive
35         Tolower       - the hash will be case sensitive, all keys are made lowercase
36         Toupper       - the hash will be case sensitive, all keys are made uppercase
37         Preserve      - the hash will be case insensitive, the case is preserved
38         Lower - the hash will be case insensitive, all keys are made lowercase
39         Upper - the hash will be case insensitive, all keys are made uppercase
40
41       If you pass a hash reference or an even list of keys and values to the
42       tie() function, those keys and values will be COPIED to the resulting
43       magical hash!
44
45       After you tie() the hash, you use it just like any other hash.
46
47   Functions
48       AddDefault
49
50               tied(%hash)->AddDefault(\%defaults);
51
52       This instructs the object to include the %defaults in the search for
53       values.  After this the value will be looked up first in %hash itself
54       and then in %defaults.
55
56       You may keep modifying the %defaults and your changes WILL be visible
57       through %hash!
58
59       You may add as many defaults to one Hash::WithDefaults object as you
60       like.
61
62       GetDefaults
63
64               $defaults = tied(%hash)->GetDefaults();
65               push @$defaults, \%another_default;
66
67       Returns a reference to the array that stores the defaults.  You may
68       delete or insert hash references into the array, but make sure you
69       NEVER EVER insert anything else than a hash reference into the array!
70
71   Config::IniHash example
72         use Config::IniHash;
73         $config = ReadIni $inifile, withdefaults => 1, insensitive => 'preserve';
74
75         if (exists $config->{':default'}) {
76           my $default = $config->{':default'};
77           foreach my $section (keys %$config) {
78             next if $section =~ /^:/;
79                 tied(%{$config->{$section}})->AddDefault($default)
80           }
81         }
82
83       And now all normal sections will get the default values from [:default]
84       section ;-)
85

AUTHOR

87       Jan Krynicky <Jenda@Krynicky.cz> http://Jenda.Krynicky.cz
88
90       Copyright (c) 2002 Jan Krynicky <Jenda@Krynicky.cz>. All rights
91       reserved.
92
93       This program is free software; you can redistribute it and/or modify it
94       under the same terms as Perl itself.
95
96
97
98perl v5.12.0                      2002-12-05                   WithDefaults(3)
Impressum