1Padre::File(3)        User Contributed Perl Documentation       Padre::File(3)
2
3
4

NAME

6       Padre::File - Common API for file functions
7

DESCRIPTION

9       "Padre::File" provides a common API for file access within Padre.  It
10       covers all the differences with non-local files by mapping every
11       function call to the currently used transport stream.
12

METHODS

14   "RegisterProtocol"
15         Padre::File->RegisterProtocol($RegExp, $Module);
16
17       Class method, may not be called on an object.
18
19       A plug-in could call "Padre::File->RegisterProtocol" to register a new
20       protocol to "Padre::File" and enable Padre to use URLs handled by this
21       module.
22
23       Example:
24
25         Padre::File->RegisterProtocol('^nfs\:\/\/','Padre::Plugin::NFS');
26
27       Every file/URL opened through "Padre::File" which starts with "nfs://"
28       is now handled through "Padre::Plugin::NFS".  "Padre::File->new()" will
29       respect this and call "Padre::Plugin::NFS->new()" to handle such URLs.
30
31       Returns true on success or false on error.
32
33       Registered protocols may override the internal protocols.
34
35   "DropProtocol"
36       Drops a previously registered protocol handler. First argument must be
37       the same regular expression (matching a protocol from an URI) that was
38       used to register the protocol handler in the first place using
39       "RegisterProtocol". Similarly, the second argument must be the name of
40       the class (module) that the handler was registered for. That means if
41       you registered your protocol with
42
43         Padre::File->RegisterProtocol(qr/^sftp:\/\//, 'Padre::File::MySFTP');
44
45       then you need to drop it with
46
47         Padre::File->DropProtocol(qr/^sftp:\/\//, 'Padre::File::MySFTP');
48
49       Returns true if a handler was removed and the empty list if no handler
50       was found for the given regular expression.
51
52   "new"
53         my $file = Padre::File->new($File_or_URL);
54
55       The "new" constructor lets you create a new "Padre::File" object.
56
57       Only one parameter is accepted at the moment: The name of the file
58       which should be used. As soon as there are HTTP, FTP, SSH and other
59       modules, also URLs should be accepted.
60
61       If you know the protocol (which should be true every time you build the
62       URL by source), it's better to call "Padre::File::Protocol->new($URL)"
63       directly (replacing Protocol by the protocol which should be used, of
64       course).
65
66       The module for the selected protocol should fill "->{filename}"
67       property. This should be used for all further references to the file as
68       it will contain the file name in universal correct format (for example
69       correct the "C:\ eq C:/" problem on Windows).
70
71       Returns a new "Padre::File" or dies on error.
72
73   "atime"
74         $file->atime;
75
76       Returns the last-access time of the file.
77
78       This is usually not possible for non-local files, in these cases, the
79       empty list is returned.
80
81   "basename"
82         $file->basename;
83
84       Returns the plain file name without path if a path/file name structure
85       exists for this module.
86
87   "blksize"
88         $file->blksize;
89
90       Returns the block size of the file system where the file resides.
91
92       This is usually not possible for non-local files, in these cases, the
93       empty list is returned.
94
95   "blocks"
96         $file->blocks;
97
98       Returns the number of blocks used by the file.
99
100       This is usually not possible for non-local files, in these cases, the
101       empty list is returned.
102
103   "browse_mtime"
104         $file->browse_mtime($path_and_filename);
105
106       Returns the modification time of the given file on the remote server.
107
108       Leave out the protocol and server name for remote protocols, for
109       example
110
111         my $file = Padre::File->new('http://perlide.org/current/foo.html');
112         $file->browse_mtime('/archive/bar.html');
113
114       This returns the modification time of
115       "http://perlide.org/archive/bar.html"
116
117       The default uses one "Padre::File" clone per request which is a
118       reasonable fallback but very inefficient! Please add "browse_X" methods
119       to the subclass module whenever possible.
120
121   "browse_url_join"
122         $file->browse_url_join($server, $path, $basename);
123
124       Merges a server name, path name and a file name to a complete URL.
125
126       A "path" in this function is meant to be the local path on the server,
127       not the Padre path (which includes the server name).
128
129       You may think of
130
131         /tmp + padre.$$                       => /tmp/padre.$$
132         C:\\temp + padre.$$                   => C:\\temp\\padre.$$
133
134       ...but also remember
135
136         http://perlide.org + about.html       => http://perlide.org/about.html
137
138       Datapoint created a file syntax...
139
140         common + program/text                 => program/text:common
141
142       This could happen once someone adds a "Padre::File::DBCFS" for using a
143       "DB/C FS" file server. "program" is the file name, "text" the extension
144       and "common" is what we call a directory.
145
146       The most common seems to be a "/" as the directory separator character,
147       so we'll use this as the default.
148
149       This method should care about merging double "/" to one if this should
150       be done on this file system (even if the default doesn't care).
151
152   "can_clone"
153         $file->can_clone;
154
155       Returns true if the protocol allows re-using of connections for new
156       files (usually from the same project).
157
158       Local files don't use connections at all, HTTP uses one-request-
159       connections, cloning has no benefit for them. FTP and SSH use
160       connections to a remote server and we should work to get no more than
161       one connection per server.
162
163   "can_run"
164         $file->can_run;
165
166       Returns true if the protocol allows execution of files or the empty
167       list if it doesn't.
168
169       This is usually not possible for non-local files (which return true),
170       because there is no way to reproduce a save environment for running a
171       HTTP or FTP based file (they return false).
172
173   "clone"
174         my $clone = $file->clone($File_or_URL);
175
176       The "clone" constructor lets you create a new "Padre::File" object
177       reusing an existing connection.
178
179       Takes the same arguments as the "new" method.
180
181       If the protocol doesn't know about (server) connections/sessions,
182       returns a brand new Padre::File object.
183
184       NOTICE: If you request a clone which is located on another server,
185       you'll
186               get a Padre::File object using the original connection to the
187               original server and the original authentication data but the
188       new
189               path and file name!
190
191       Returns a new "Padre::File" or dies on error.
192
193   "clone_file"
194         my $clone = $file->clone_file($filename_with_path);
195         my $clone = $file->clone_file($path,$filename);
196
197       The "clone" constructor lets you create a new "Padre::File" object
198       reusing an existing connection.
199
200       Takes one or two arguments:
201
202       either the complete path + file name of an URL
203       or the path and file name as separate arguments
204
205       If the protocol doesn't know about (server) connections/sessions,
206       returns a brand new "Padre::File" object.
207
208       Returns a new "Padre::File" or dies on error.
209
210   "ctime"
211         $file->ctime;
212
213       Returns the last-change time of the inode (not the file!).
214
215       This is usually not possible for non-local files, in these cases, the
216       empty list is returned.
217
218   "dev"
219         $file->dev;
220
221       Returns the device number of the file system where the file resides.
222
223       This is usually not possible for non-local files, in these cases, the
224       empty list is returned.
225
226   "dirname"
227         $file->dirname;
228
229       Returns the plain path without file name if a path/file name structure
230       exists for this module.
231
232       Returns the empty list on failure or undefined behaviour for the given
233       protocol.
234
235   "error"
236         $file->error;
237
238       Returns the last error message (like $! for system calls).
239
240   "exists"
241         $file->exists;
242
243       Returns true if the file exists.  Returns false if the file doesn't
244       exist.  Returns the empty list if unsure (network problem, not
245       implemented).
246
247   "filename"
248         $file->filename;
249
250       Returns the the file name including path handled by this object.
251
252       Please remember that "Padre::File" is able to open many URL types. This
253       file name may also be a URL. Please use the "basename" and "dirname"
254       methods to split it (assuming that a path exists in the current
255       protocol).
256
257   "gid"
258         $file->gid;
259
260       Returns the real group ID of the file group.
261
262       This is usually not possible for non-local files, in these cases, the
263       empty list is returned.
264
265   "inode"
266         $file->inode;
267
268       Returns the inode number of the file.
269
270       This is usually not possible for non-local files, in these cases, the
271       empty list is returned.
272
273   "mime"
274         $file->mime;
275         $file->mime('text/plain');
276
277       Returns or sets the MIME type of the file.
278
279   "mode"
280         $file->mode;
281
282       Returns the file mode (type and rights). See also: "stat" in perlfunc.
283       To get the POSIX file permissions as the usual octal number (as opposed
284       to a string) use:
285
286         use Fcntl ':mode';
287         my $perms_octal = S_IMODE($file->mode);
288
289       This is usually not possible for non-local files, in these cases, the
290       empty list is returned.
291
292   "mtime"
293         $file->mtime;
294
295       Returns the last-modification (change) time of the file.
296
297   "nlink"
298         $file->nlink;
299
300       Returns the number of hard links to the file.
301
302       This is usually not possible for non-local files, in these cases, the
303       empty list is returned.
304
305   "rdev"
306         $file->rdev;
307
308       Returns the device identifier.
309
310       This is usually not possible for non-local files, in these cases, the
311       empty list is returned.
312
313   "read"
314         $file->read;
315
316       Reads the file contents and returns them.
317
318       Returns the empty list on error. The error message can be retrieved
319       using the "error" method.
320
321   "servername"
322         $file->servername;
323
324       Returns the server name for this module - if the protocol knows about a
325       server, local files don't.
326
327       WARNING: The Padre "path" includes the server name in a protocol
328       dependent
329                syntax!
330
331   "size"
332         $file->size;
333
334       Returns the file size in bytes or the empty list if the method was not
335       implemented by the "Padre::File" subclass.
336
337   "stat"
338         $file->stat;
339
340       This emulates a stat call and returns the same values:
341
342         0 dev      device number of file system
343         1 ino      inode number
344         2 mode     file mode  (type and permissions)
345         3 nlink    number of (hard) links to the file
346         4 uid      numeric user ID of file's owner
347         5 gid      numeric group ID of file's owner
348         6 rdev     the device identifier (special files only)
349         7 size     total size of file, in bytes
350         8 atime    last access time in seconds since the epoch
351         9 mtime    last modify time in seconds since the epoch
352        10 ctime    inode change time in seconds since the epoch (*)
353        11 blksize  preferred block size for file system I/O
354        12 blocks   actual number of blocks allocated
355
356       A module should fill as many items as possible, but if you're thinking
357       about using this method, always remember
358
359       1.  Usually, you need only one or two of the items, request them
360           directly.
361
362       2.  Besides from local files, most of the values will not be accessible
363           (resulting in empty lists/false returned).
364
365       3.  On most protocols these values must be requested one-by-one, which
366           is very expensive.
367
368       Please always consider using the function for the value you really need
369       instead of using "stat"!
370
371   "uid"
372         $file->uid;
373
374       Returns the real user ID of the file owner.
375
376       This is usually not possible for non-local files, in these cases, the
377       empty list is returned.
378
379   "write"
380         $file->write($Content);
381         $file->write($Content,$Coding);
382
383       Writes the given $Content to the file, if a encoding is given and the
384       protocol allows encoding, it is respected.
385
386       Returns 1 on success.  Returns 0 on failure.  Returns the empty list if
387       the function is not available on the protocol.
388

INTERNAL METHODS

390   "_info"
391         $file->_info($message);
392
393       Shows $message to the user as an information. The output is guaranteed
394       to be non-blocking and messages shown this way must be safe to be
395       ignored by the user.
396
397       Doesn't return anything.
398
399
400
401perl v5.12.1                      2010-06-11                    Padre::File(3)
Impressum