.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Hierarchy 3" .TH Hierarchy 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Data::Hierarchy \- Handle data in a hierarchical structure .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 4 \& my $tree = Data::Hierarchy\->new(); \& $tree\->store (\*(Aq/\*(Aq, {access => \*(Aqall\*(Aq}); \& $tree\->store (\*(Aq/private\*(Aq, {access => \*(Aqauth\*(Aq, \& \*(Aq.note\*(Aq => \*(Aqthis is private}); \& \& $info = $tree\->get (\*(Aq/private/somewhere/deep\*(Aq); \& \& # return actual data points in list context \& ($info, @fromwhere) = $tree\->get (\*(Aq/private/somewhere/deep\*(Aq); \& \& my @items = $tree\->find (\*(Aq/\*(Aq, {access => qr/.*/}); \& \& # override all children \& $tree\->store (\*(Aq/\*(Aq, {\*(Aq.note\*(Aq => undef}, {override_sticky_descendents => 1}); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Data::Hierarchy provides a simple interface for manipulating inheritable data attached to a hierarchical environment (like a filesystem). .PP One use of Data::Hierarchy is to allow an application to annotate paths in a real filesystem in a single compact data structure. However, the hierarchy does not actually need to correspond to an actual filesystem. .PP Paths in a hierarchy are referred to in a Unix-like syntax; \f(CW"/"\fR is the root "directory". (You can specify a different separator character than the slash when you construct a Data::Hierarchy object.) With the exception of the root path, paths should never contain trailing slashes. You can associate properties, which are arbitrary name/value pairs, with any path. (Properties cannot contain the undefined value.) By default, properties are inherited by child paths: thus, if you store some data at \f(CW\*(C`/some/path\*(C'\fR: .PP .Vb 1 \& $tree\->store(\*(Aq/some/path\*(Aq, {color => \*(Aqred\*(Aq}); .Ve .PP you can fetch it again at a \f(CW\*(C`/some/path/below/that\*(C'\fR: .PP .Vb 2 \& print $tree\->get(\*(Aq/some/path/below/that\*(Aq)\->{\*(Aqcolor\*(Aq}; \& # prints red .Ve .PP On the other hand, properties whose names begin with dots are uninherited, or "sticky": .PP .Vb 3 \& $tree\->store(\*(Aq/some/path\*(Aq, {\*(Aq.color\*(Aq => \*(Aqblue\*(Aq}); \& print $tree\->get(\*(Aq/some/path\*(Aq)\->{\*(Aq.color\*(Aq}; # prints blue \& print $tree\->get(\*(Aq/some/path/below/that\*(Aq)\->{\*(Aq.color\*(Aq}; # undefined .Ve .PP Note that you do not need to (and in fact, cannot) explicitly add "files" or "directories" to the hierarchy; you simply add and delete properties to paths. .SH CONSTRUCTOR .IX Header "CONSTRUCTOR" Creates a new hierarchy object. Takes the following options: .IP sep 4 .IX Item "sep" The string used as a separator between path levels. Defaults to '/'. .SH METHODS .IX Header "METHODS" .SS "Instance Methods" .IX Subsection "Instance Methods" .ie n .IP """store $path, $properties, {%options}""" 4 .el .IP "\f(CWstore $path, $properties, {%options}\fR" 4 .IX Item "store $path, $properties, {%options}" Given a path and a hash reference of properties, stores the properties at the path. .Sp Unless the \f(CW\*(C`override_descendents\*(C'\fR option is given with a false value, it eliminates any non-sticky property in a descendent of \f(CW$path\fR with the same name. .Sp If the \f(CW\*(C`override_sticky_descendents\*(C'\fR option is given with a true value, it eliminates any sticky property in a descendent of \f(CW$path\fR with the same name. override it. .Sp A value of undef removes that value; note, though, that if an ancestor of \f(CW$path\fR defines that property, the ancestor's value will be inherited there; that is, with: .Sp .Vb 4 \& $t\->store(\*(Aq/a\*(Aq, {k => \*(Aqtop\*(Aq}); \& $t\->store(\*(Aq/a/b\*(Aq, {k => \*(Aqbottom\*(Aq}); \& $t\->store(\*(Aq/a/b\*(Aq, {k => undef}); \& print $t\->get(\*(Aq/a/b\*(Aq)\->{\*(Aqk\*(Aq}; .Ve .Sp it will print 'top'. .ie n .IP """get $path, [$dont_clone]""" 4 .el .IP "\f(CWget $path, [$dont_clone]\fR" 4 .IX Item "get $path, [$dont_clone]" Given a path, looks up all of the properteies (sticky and not) and returns them in a hash reference. The values are clones, unless you pass a true value for \f(CW$dont_clone\fR. .Sp If called in list context, returns that hash reference followed by all of the ancestral paths of \f(CW$path\fR which contain non-sticky properties (possibly including itself). .ie n .IP """find $path, $property_regexps""" 4 .el .IP "\f(CWfind $path, $property_regexps\fR" 4 .IX Item "find $path, $property_regexps" Given a path and a hash reference of name/regular expression pairs, returns a list of all paths which are descendents of \f(CW$path\fR (including itself) and define \fBat that path itself\fR (not inherited) all of the properties in the hash with values matching the given regular expressions. (You may want to use \f(CW\*(C`qr/.*/\*(C'\fR to merely see if it has any value defined there.) Properties can be sticky or not. .ie n .IP """merge $other_hierarchy, $path""" 4 .el .IP "\f(CWmerge $other_hierarchy, $path\fR" 4 .IX Item "merge $other_hierarchy, $path" Given a second Data::Hierarchy object and a path, copies all the properties from the other object at \f(CW$path\fR or below into the corresponding paths in the object this method is invoked on. All properties from the object this is invoked on at \f(CW$path\fR or below are erased first. .ie n .IP """to_relative $base_path""" 4 .el .IP "\f(CWto_relative $base_path\fR" 4 .IX Item "to_relative $base_path" Given a path which \fBevery\fR element of the hierarchy must be contained in, returns a special Data::Hierarchy::Relative object which represents the hierarchy relative that path. The \fBonly\fR thing you can do with a Data::Hierarchy::Relative object is call \&\f(CWto_absolute($new_base_path)\fR on it, which returns a new Data::Hierarchy object at that base path. For example, if everything in the hierarchy is rooted at \f(CW\*(C`/home/super_project\*(C'\fR and it needs to be moved to \f(CW\*(C`/home/awesome_project\*(C'\fR, you can do .Sp .Vb 1 \& $hierarchy = $hierarchy\->to_relative(\*(Aq/home/super_project\*(Aq)\->to_absolute(\*(Aq/home/awesome_project\*(Aq); .Ve .Sp (Data::Hierarchy::Relative objects may be a more convenient serialization format than Data::Hierarchy objects, if they are tracking the state of some relocatable resource.) .SH AUTHORS .IX Header "AUTHORS" Chia-liang Kao David Glasser .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2003\-2006 by Chia-liang Kao . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See