1SVK::Util(3) User Contributed Perl Documentation SVK::Util(3)
2
3
4
6 SVK::Util - Utility functions for SVK classes
7
9 use SVK::Util qw( func1 func2 func3 )
10
12 This is yet another abstraction function set for portable file, buffer
13 and IO handling, tailored to SVK's specific needs.
14
15 No symbols are exported by default; the user module needs to specify
16 the list of functions to import.
17
19 Constant Functions
20
21 IS_WIN32
22
23 Boolean flag to indicate whether this system is running Microsoft Win‐
24 dows.
25
26 DEFAULT_EDITOR
27
28 The default program to invoke for editing buffers: "notepad.exe" on
29 Win32, "vi" otherwise.
30
31 TEXT_MODE
32
33 The I/O layer for text files: ":crlf" on Win32, empty otherwise.
34
35 HAS_SYMLINK
36
37 Boolean flag to indicate whether this system supports "symlink()".
38
39 HAS_SVN_MIRROR
40
41 Boolean flag to indicate whether we can successfully load SVN::Mirror.
42
43 Constant Scalars
44
45 $SEP
46
47 Native path separator: platform: "\" on dosish platforms, "/" other‐
48 wise.
49
50 $EOL
51
52 End of line marker: "\015\012" on Win32, "\012" otherwise.
53
55 User Interactivity
56
57 get_prompt ($prompt, $pattern)
58
59 Repeatedly prompt the user for a line of answer, until it matches the
60 regular expression pattern. Returns the chomped answer line.
61
62 edit_file ($file_name)
63
64 Launch editor to edit a file.
65
66 get_buffer_from_editor ($what, $sep, $content, $filename, $anchor,
67 $targets_ref)
68
69 XXX Undocumented
70
71 get_encoding
72
73 Get the current encoding from locale
74
75 get_encoder ([$encoding])
76
77 from_native ($octets, $what, [$encoding])
78
79 to_native ($octets, $what, [$encoding])
80
81 File Content Manipulation
82
83 read_file ($filename)
84
85 Read from a file and returns its content as a single scalar.
86
87 write_file ($filename, $content)
88
89 Write out content to a file, overwriting existing content if present.
90
91 slurp_fh ($input_fh, $output_fh)
92
93 Read all data from the input filehandle and write them to the output
94 filehandle. The input may also be a scalar, or reference to a scalar.
95
96 md5_fh ($input_fh)
97
98 Calculate MD5 checksum for data in the input filehandle.
99
100 mimetype ($file)
101
102 Return the MIME type for the file, or "undef" if the MIME database is
103 missing on the system.
104
105 mimetype_is_text ($mimetype)
106
107 Return whether a MIME type string looks like a text file.
108
109 is_binary_file ($filename OR $filehandle)
110
111 Returns true if the given file or filehandle contains binary data.
112 Otherwise, returns false.
113
114 Path and Filename Handling
115
116 abspath ($path)
117
118 Return paths with components in symlink resolved, but keep the final
119 path even if it's symlink. Returns "undef" if the base directory does
120 not exist.
121
122 abs_path_noexist ($path)
123
124 Return paths with components in symlink resolved, but keep the final
125 path even if it's symlink. Unlike abs_path(), returns a valid value
126 even if the base directory doesn't exist.
127
128 abs2rel ($pathname, $old_basedir, $new_basedir, $sep)
129
130 Replace the base directory in the native pathname to another base
131 directory and return the result.
132
133 If the pathname is not under $old_basedir, it is returned unmodified.
134
135 If $new_basedir is an empty string, removes the old base directory but
136 keeps the leading slash. If $new_basedir is "undef", also removes the
137 leading slash.
138
139 By default, the return value of this function will use $SEP as its path
140 separator. Setting $sep to "/" will turn native path separators into
141 "/" instead.
142
143 catdir (@directories)
144
145 Concatenate directory names to form a complete path; also removes the
146 trailing slash from the resulting string, unless it is the root direc‐
147 tory.
148
149 catfile (@directories, $pathname)
150
151 Concatenate one or more directory names and a filename to form a com‐
152 plete path, ending with a filename. If $pathname contains directories,
153 they will be splitted off to the end of @directories.
154
155 catpath ($volume, $directory, $filename)
156
157 XXX Undocumented - See File::Spec
158
159 devnull ()
160
161 Return a file name suitable for reading, and guaranteed to be empty.
162
163 get_anchor ($need_target, @paths)
164
165 Returns the (anchor, target) pairs for native path @paths. Discard the
166 targets being returned unless $need_target.
167
168 get_depot_anchor ($need_target, @paths)
169
170 Returns the (anchor, target) pairs for depotpaths @paths. Discard the
171 targets being returned unless $need_target.
172
173 catdepot ($depot_name, @paths)
174
175 make_path ($path)
176
177 Create a directory, and intermediate directories as required.
178
179 splitpath ($path)
180
181 Splits a path in to volume, directory, and filename portions. On sys‐
182 tems with no concept of volume, returns an empty string for volume.
183
184 splitdir ($path)
185
186 The opposite of "catdir()"; return a list of path components.
187
188 tmpdir ()
189
190 Return the name of the first writable directory from a list of possible
191 temporary directories.
192
193 tmpfile (TEXT => $is_textmode, %args)
194
195 In scalar context, return the filehandle of a temporary file. In list
196 context, return the filehandle and the filename.
197
198 If $is_textmode is true, the returned file handle is marked with
199 "TEXT_MODE".
200
201 See File::Temp for valid keys of %args.
202
203 is_symlink ($filename)
204
205 Return whether a file is a symbolic link, as determined by "-l". If
206 $filename is not specified, return "-l _" instead.
207
208 is_executable ($filename)
209
210 Return whether a file is likely to be an executable file. Unlike
211 "is_symlink()", the $filename argument is not optional.
212
213 can_run ($filename)
214
215 Check if we can run some command.
216
217 is_uri ($string)
218
219 Check if a string is a valid URI.
220
221 move_path ($source, $target)
222
223 Move a path to another place, creating intermediate directories in the
224 target path if neccessary. If move failed, tell the user to move it
225 manually.
226
227 traverse_history (root => $fs_root, path => $path, cross => $cross,
228 callback => $cb($path, $revision))
229
230 Traverse the history of $path in $fs_root backwards until the first
231 copy, unless $cross is true. We do cross renames regardless of the
232 value of $cross being non-zero, but not -1. We invoke $cb for each
233 $path, $revision we encounter. If cb returns a nonzero value we stop
234 traversing as well.
235
236 is_path_inside($path, $parent)
237
238 Returns true if unix path $path is inside $parent. If they are the
239 same, return true as well.
240
241
242
243perl v5.8.8 2006-12-28 SVK::Util(3)