1Tree::Simple::Visitor::UCsreeratCeoDnitrreicbTturotereeyd:T:rPSeeierm(lp3l)Deo:c:uVmiesnittaotri:o:nCreateDirectoryTree(3)
2
3
4
6 Tree::Simple::Visitor::CreateDirectoryTree - A Visitor for create a set
7 of directories and files from a Tree::Simple object
8
10 use Tree::Simple::Visitor::CreateDirectoryTree;
11
12 # create a Tree::Simple object which
13 # represents a directory heirarchy
14 my $tree = Tree::Simple->new("www/")
15 ->addChildren(
16 Tree::Simple->new("conf/")
17 ->addChildren(
18 Tree::Simple->new("startup.pl"),
19 Tree::Simple->new("httpd.conf")
20 ),
21 Tree::Simple->new("cgi-bin/"),
22 Tree::Simple->new("ht_docs/"),
23 Tree::Simple->new("logs/")
24 ->addChildren(
25 Tree::Simple->new("error.log"),
26 Tree::Simple->new("access.log")
27 ),
28 );
29
30 # create an instance of our visitor
31 my $visitor = Tree::Simple::Visitor::CreateDirectoryTree->new();
32
33 # pass the visitor to a Tree::Simple object
34 $tree->accept($visitor);
35
36 # the www/ directory now mirrors the structure of the tree
37
39 This visitor can be used to create a set of directories and files from
40 a Tree::Simple object hierarchy.
41
43 new There are no arguments to the constructor the object will be in its
44 default state. You can use the "setNodeFilter", "setFileHandler"
45 and "setDirectoryHandler" methods to customize its behavior.
46
47 setNodeFilter ($filter_function)
48 This method accepts a CODE reference as its $filter_function
49 argument and throws an exception if it is not a code reference.
50 This code reference is used to filter the tree nodes as they are
51 used to create the directory tree, it can be basically used as a
52 node pre-processor. An example usage of this might be to enforce
53 the 8.3 naming rules of DOS, or the 32 character limit of older
54 macintoshes.
55
56 setFileHandler ($file_handler)
57 This method accepts a CODE reference as its $file_handler argument
58 and throws an exception if it is not a CODE reference. This method
59 can be used to create custom file creation behavior. The default
60 behavior is to just create the file and nothing else, but by using
61 this method it is possible to implement some other custom behavior,
62 such as creating a file based on a template. The function is passed
63 the full path of the file to be created (as built by File::Spec).
64
65 setDirectoryHandler ($dir_handler)
66 This method accepts a CODE reference as its $dir_handler argument
67 and throws an exception if it is not a CODE reference. This method
68 can be used to create custom directory creation behavior. The
69 default behavior is to just create the directory and nothing else,
70 but by using this method it is possible to implement some other
71 custom behavior, such as creating a directory on a remote server.
72 The function is passed the full path of the directory to be created
73 (as built by File::Spec).
74
75 visit ($tree)
76 This is the method that is used by Tree::Simple's "accept" method.
77 It can also be used on its own, it requires the $tree argument to
78 be a Tree::Simple object (or derived from a Tree::Simple object),
79 and will throw and exception otherwise.
80
81 The tree is processed as follows:
82
83 Any node which is not a leaf is considered a directory.
84 Obviously since files themselves are leaf nodes, this makes
85 sense that non-leaves will be directories.
86
87 Any node (including leaf nodes) which ends in either the character
88 "/" or "\" is considered a directory.
89 I think it is a pretty standard convention to have directory
90 names ending in a seperator. The seperator itself is stripped
91 off before the directory name is passed to File::Spec where the
92 platform specific directory path is created. This means that it
93 does not matter which one you use, it will be completely cross
94 platform (at least as cross-platform as File::Spec is).
95
96 All other nodes are considered to be files.
97
99 None that I am aware of. Of course, if you find a bug, let me know, and
100 I will be sure to fix it.
101
103 See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more
104 inforamtion.
105
107 These Visitor classes are all subclasses of Tree::Simple::Visitor,
108 which can be found in the Tree::Simple module, you should refer to that
109 module for more information.
110
112 stevan little, <stevan@iinteractive.com>
113
115 Copyright 2004, 2005 by Infinity Interactive, Inc.
116
117 <http://www.iinteractive.com>
118
119 This library is free software; you can redistribute it and/or modify it
120 under the same terms as Perl itself.
121
122
123
124perl v5.12.0 T2r0e0e5:-:0S7i-m1p4le::Visitor::CreateDirectoryTree(3)