1Mixin::ExtraFields::DriUvseerr::CHoansthrGiubtust(e3d)PMeirxlinD:o:cEuxmternatFaiteilodns::Driver::HashGuts(3)
2
3
4
6 Mixin::ExtraFields::Driver::HashGuts - store extras in a hashy object's
7 guts
8
10 version 0.140003
11
13 package Your::HashBased::Class;
14
15 use Mixin::ExtraFields -fields => { driver => 'HashGuts' };
16
18 This driver class implements an extremely simple storage mechanism:
19 extras are stored on the object on which the mixed-in methods are
20 called. By default, they are stored under the key returned by the
21 "default_has_key" method, but this can be changed by providing a
22 "hash_key" argument to the driver configuration, like so:
23
24 use Mixin::ExtraFields -fields => {
25 driver => { class => 'HashGuts', hash_key => "\0Something\0Wicked\0" }
26 };
27
29 This library should run on perls released even a long time ago. It
30 should work on any version of perl released in the last five years.
31
32 Although it may work on older versions of perl, no guarantee is made
33 that the minimum required version will not be increased. The version
34 may be increased for any reason, and there is no promise that patches
35 will be accepted to lower the minimum required perl.
36
38 In addition to the methods required by Mixin::ExtraFields::Driver, the
39 following methods are provided:
40
41 hash_key
42 my $key = $driver->hash_key;
43
44 This method returns the key where the driver will store its extras.
45
46 default_hash_key
47 If no "hash_key" argument is given for the driver, this method is
48 called during driver initialization. It will return a unique string to
49 be used as the hash key.
50
51 storage
52 This method returns the hashref of storage used for extras. Individual
53 objects get weak references to their id within this hashref.
54
55 storage_for
56 my $stash = $driver->storage_for($object, $id);
57
58 This method returns the hashref to use to store extras for the given
59 object and id. This hashref is stored on both the hash-based object
60 (in its "hash_key" entry) and on the driver (in the entry for $id in
61 its "storage" hash).
62
63 All objects with the same id should end up with the same hash in their
64 "hash_key" field. None of these references are weakened, which means
65 two things: first, even if all objects with a given id go out of
66 scope, future objects with that id will retain the original extras;
67 secondly, memory used to store extras is never reclaimed. If this is a
68 problem, use a more sophisticated driver.
69
71 Ricardo Signes <cpan@semiotic.systems>
72
74 This software is copyright (c) 2022 by Ricardo Signes.
75
76 This is free software; you can redistribute it and/or modify it under
77 the same terms as the Perl 5 programming language system itself.
78
79
80
81perl v5.38.0 2023-0M7i-x2i0n::ExtraFields::Driver::HashGuts(3)