.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Padre::File 3pm" .TH Padre::File 3pm "2012-06-27" "perl v5.14.2" "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" Padre::File \- Common API for file functions .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Padre::File\*(C'\fR provides a common \s-1API\s0 for file access within Padre. It covers all the differences with non-local files by mapping every function call to the currently used transport stream. .SH "METHODS" .IX Header "METHODS" .ie n .SS """RegisterProtocol""" .el .SS "\f(CWRegisterProtocol\fP" .IX Subsection "RegisterProtocol" .Vb 1 \& Padre::File\->RegisterProtocol($RegExp, $Module); .Ve .PP Class method, may not be called on an object. .PP A plug-in could call \f(CW\*(C`Padre::File\->RegisterProtocol\*(C'\fR to register a new protocol to \&\f(CW\*(C`Padre::File\*(C'\fR and enable Padre to use URLs handled by this module. .PP Example: .PP .Vb 1 \& Padre::File\->RegisterProtocol(\*(Aq^nfs\e:\e/\e/\*(Aq,\*(AqPadre::Plugin::NFS\*(Aq); .Ve .PP Every file/URL opened through \f(CW\*(C`Padre::File\*(C'\fR which starts with \f(CW\*(C`nfs://\*(C'\fR is now handled through \f(CW\*(C`Padre::Plugin::NFS\*(C'\fR. \&\f(CW\*(C`Padre::File\->new\*(C'\fR will respect this and call \f(CW\*(C`Padre::Plugin::NFS\->new\*(C'\fR to handle such URLs. .PP Returns true on success or false on error. .PP Registered protocols may override the internal protocols. .ie n .SS """DropProtocol""" .el .SS "\f(CWDropProtocol\fP" .IX Subsection "DropProtocol" Drops a previously registered protocol handler. First argument must be the same regular expression (matching a protocol from an \s-1URI\s0) that was used to register the protocol handler in the first place using \&\f(CW\*(C`RegisterProtocol\*(C'\fR. Similarly, the second argument must be the name of the class (module) that the handler was registered for. That means if you registered your protocol with .PP .Vb 1 \& Padre::File\->RegisterProtocol(qr/^sftp:\e/\e//, \*(AqPadre::File::MySFTP\*(Aq); .Ve .PP then you need to drop it with .PP .Vb 1 \& Padre::File\->DropProtocol(qr/^sftp:\e/\e//, \*(AqPadre::File::MySFTP\*(Aq); .Ve .PP Returns true if a handler was removed and the empty list if no handler was found for the given regular expression. .ie n .SS """new""" .el .SS "\f(CWnew\fP" .IX Subsection "new" .Vb 1 \& my $file = Padre::File\->new($File_or_URL); .Ve .PP The \f(CW\*(C`new\*(C'\fR constructor lets you create a new \f(CW\*(C`Padre::File\*(C'\fR object. .PP Only one parameter is accepted at the moment: The name of the file which should be used. As soon as there are \s-1HTTP\s0, \s-1FTP\s0, \s-1SSH\s0 and other modules, also URLs should be accepted. .PP If you know the protocol (which should be true every time you build the \s-1URL\s0 by source), it's better to call \f(CW\*(C`Padre::File::Protocol\->new($URL)\*(C'\fR directly (replacing Protocol by the protocol which should be used, of course). .PP The module for the selected protocol should fill \f(CW\*(C`\->{filename}\*(C'\fR property. This should be used for all further references to the file as it will contain the file name in universal correct format (for example correct the \f(CW\*(C`C:\e eq C:/\*(C'\fR problem on Windows). .PP Returns a new \f(CW\*(C`Padre::File\*(C'\fR or dies on error. .ie n .SS """atime""" .el .SS "\f(CWatime\fP" .IX Subsection "atime" .Vb 1 \& $file\->atime; .Ve .PP Returns the last-access time of the file. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """basename""" .el .SS "\f(CWbasename\fP" .IX Subsection "basename" .Vb 1 \& $file\->basename; .Ve .PP Returns the plain file name without path if a path/file name structure exists for this module. .ie n .SS """blksize""" .el .SS "\f(CWblksize\fP" .IX Subsection "blksize" .Vb 1 \& $file\->blksize; .Ve .PP Returns the block size of the file system where the file resides. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """blocks""" .el .SS "\f(CWblocks\fP" .IX Subsection "blocks" .Vb 1 \& $file\->blocks; .Ve .PP Returns the number of blocks used by the file. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """browse_mtime""" .el .SS "\f(CWbrowse_mtime\fP" .IX Subsection "browse_mtime" .Vb 1 \& $file\->browse_mtime($path_and_filename); .Ve .PP Returns the modification time of the given file on the remote server. .PP Leave out the protocol and server name for remote protocols, for example .PP .Vb 2 \& my $file = Padre::File\->new(\*(Aqhttp://perlide.org/current/foo.html\*(Aq); \& $file\->browse_mtime(\*(Aq/archive/bar.html\*(Aq); .Ve .PP This returns the modification time of \f(CW\*(C`http://perlide.org/archive/bar.html\*(C'\fR .PP The default uses one \f(CW\*(C`Padre::File\*(C'\fR clone per request which is a reasonable fallback but very inefficient! Please add \f(CW\*(C`browse_X\*(C'\fR methods to the subclass module whenever possible. .ie n .SS """browse_url_join""" .el .SS "\f(CWbrowse_url_join\fP" .IX Subsection "browse_url_join" .Vb 1 \& $file\->browse_url_join($server, $path, $basename); .Ve .PP Merges a server name, path name and a file name to a complete \s-1URL\s0. .PP A \f(CW\*(C`path\*(C'\fR in this function is meant to be the local path on the server, not the Padre path (which includes the server name). .PP You may think of .PP .Vb 2 \& /tmp + padre.$$ => /tmp/padre.$$ \& C:\e\etemp + padre.$$ => C:\e\etemp\e\epadre.$$ .Ve .PP \&...but also remember .PP .Vb 1 \& http://perlide.org + about.html => http://perlide.org/about.html .Ve .PP Datapoint created a file syntax... .PP .Vb 1 \& common + program/text => program/text:common .Ve .PP This could happen once someone adds a \f(CW\*(C`Padre::File::DBCFS\*(C'\fR for using a \f(CW\*(C`DB/C FS\*(C'\fR file server. \f(CW\*(C`program\*(C'\fR is the file name, \f(CW\*(C`text\*(C'\fR the extension and \*(L"common\*(R" is what we call a directory. .PP The most common seems to be a \f(CW\*(C`/\*(C'\fR as the directory separator character, so we'll use this as the default. .PP This method should care about merging double \f(CW\*(C`/\*(C'\fR to one if this should be done on this file system (even if the default doesn't care). .ie n .SS """can_clone""" .el .SS "\f(CWcan_clone\fP" .IX Subsection "can_clone" .Vb 1 \& $file\->can_clone; .Ve .PP Returns true if the protocol allows re-using of connections for new files (usually from the same project). .PP Local files don't use connections at all, \s-1HTTP\s0 uses one\-request\- connections, cloning has no benefit for them. \s-1FTP\s0 and \s-1SSH\s0 use connections to a remote server and we should work to get no more than one connection per server. .ie n .SS """can_delete""" .el .SS "\f(CWcan_delete\fP" .IX Subsection "can_delete" .Vb 1 \& $file\->can_delete; .Ve .PP Returns true if the protocol allows deletion of files or false if it doesn't. .ie n .SS """can_run""" .el .SS "\f(CWcan_run\fP" .IX Subsection "can_run" .Vb 1 \& $file\->can_run; .Ve .PP Returns true if the protocol allows execution of files or the empty list if it doesn't. .PP This is usually not possible for non-local files (which return true), because there is no way to reproduce a save environment for running a \s-1HTTP\s0 or \s-1FTP\s0 based file (they return false). .ie n .SS """clone""" .el .SS "\f(CWclone\fP" .IX Subsection "clone" .Vb 1 \& my $clone = $file\->clone($File_or_URL); .Ve .PP The \f(CW\*(C`clone\*(C'\fR constructor lets you create a new \f(CW\*(C`Padre::File\*(C'\fR object reusing an existing connection. .PP Takes the same arguments as the \f(CW\*(C`new\*(C'\fR method. .PP If the protocol doesn't know about (server) connections/sessions, returns a brand new Padre::File object. .PP \&\s-1NOTICE:\s0 If you request a clone which is located on another server, you'll get a Padre::File object using the original connection to the original server and the original authentication data but the new path and file name! .PP Returns a new \f(CW\*(C`Padre::File\*(C'\fR or dies on error. .ie n .SS """clone_file""" .el .SS "\f(CWclone_file\fP" .IX Subsection "clone_file" .Vb 2 \& my $clone = $file\->clone_file($filename_with_path); \& my $clone = $file\->clone_file($path,$filename); .Ve .PP The \f(CW\*(C`clone\*(C'\fR constructor lets you create a new \f(CW\*(C`Padre::File\*(C'\fR object reusing an existing connection. .PP Takes one or two arguments: .IP "either the complete path + file name of an \s-1URL\s0" 4 .IX Item "either the complete path + file name of an URL" .PD 0 .IP "or the path and file name as separate arguments" 4 .IX Item "or the path and file name as separate arguments" .PD .PP If the protocol doesn't know about (server) connections/sessions, returns a brand new \f(CW\*(C`Padre::File\*(C'\fR object. .PP Returns a new \f(CW\*(C`Padre::File\*(C'\fR or dies on error. .ie n .SS """ctime""" .el .SS "\f(CWctime\fP" .IX Subsection "ctime" .Vb 1 \& $file\->ctime; .Ve .PP Returns the last-change time of the inode (not the file!). .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """delete""" .el .SS "\f(CWdelete\fP" .IX Subsection "delete" .Vb 1 \& $file\->delete; .Ve .PP Removes the current object's file from disk (or whereever it's stored). .PP Should clear any caches. .ie n .SS """dev""" .el .SS "\f(CWdev\fP" .IX Subsection "dev" .Vb 1 \& $file\->dev; .Ve .PP Returns the device number of the file system where the file resides. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """dirname""" .el .SS "\f(CWdirname\fP" .IX Subsection "dirname" .Vb 1 \& $file\->dirname; .Ve .PP Returns the plain path without file name if a path/file name structure exists for this module. .PP Returns the empty list on failure or undefined behaviour for the given protocol. .ie n .SS """error""" .el .SS "\f(CWerror\fP" .IX Subsection "error" .Vb 1 \& $file\->error; .Ve .PP Returns the last error message (like $! for system calls). .ie n .SS """exists""" .el .SS "\f(CWexists\fP" .IX Subsection "exists" .Vb 1 \& $file\->exists; .Ve .PP Returns true if the file exists. Returns false if the file doesn't exist. Returns the empty list if unsure (network problem, not implemented). .ie n .SS """filename""" .el .SS "\f(CWfilename\fP" .IX Subsection "filename" .Vb 1 \& $file\->filename; .Ve .PP Returns the the file name including path handled by this object. .PP Please remember that \f(CW\*(C`Padre::File\*(C'\fR is able to open many \s-1URL\s0 types. This file name may also be a \s-1URL\s0. Please use the \f(CW\*(C`basename\*(C'\fR and \f(CW\*(C`dirname\*(C'\fR methods to split it (assuming that a path exists in the current protocol). .ie n .SS """gid""" .el .SS "\f(CWgid\fP" .IX Subsection "gid" .Vb 1 \& $file\->gid; .Ve .PP Returns the real group \s-1ID\s0 of the file group. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """inode""" .el .SS "\f(CWinode\fP" .IX Subsection "inode" .Vb 1 \& $file\->inode; .Ve .PP Returns the inode number of the file. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """mime""" .el .SS "\f(CWmime\fP" .IX Subsection "mime" .Vb 2 \& $file\->mime; \& $file\->mime(\*(Aqtext/plain\*(Aq); .Ve .PP Returns or sets the \s-1MIME\s0 type of the file. .ie n .SS """mode""" .el .SS "\f(CWmode\fP" .IX Subsection "mode" .Vb 1 \& $file\->mode; .Ve .PP Returns the file mode (type and rights). See also: \*(L"stat\*(R" in perlfunc. To get the \s-1POSIX\s0 file \fIpermissions\fR as the usual octal \fInumber\fR (as opposed to a \fIstring\fR) use: .PP .Vb 2 \& use Fcntl \*(Aq:mode\*(Aq; \& my $perms_octal = S_IMODE($file\->mode); .Ve .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """mtime""" .el .SS "\f(CWmtime\fP" .IX Subsection "mtime" .Vb 1 \& $file\->mtime; .Ve .PP Returns the last-modification (change) time of the file. .ie n .SS """nlink""" .el .SS "\f(CWnlink\fP" .IX Subsection "nlink" .Vb 1 \& $file\->nlink; .Ve .PP Returns the number of hard links to the file. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """rdev""" .el .SS "\f(CWrdev\fP" .IX Subsection "rdev" .Vb 1 \& $file\->rdev; .Ve .PP Returns the device identifier. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """read""" .el .SS "\f(CWread\fP" .IX Subsection "read" .Vb 1 \& $file\->read; .Ve .PP Reads the file contents and returns them. .PP Returns the empty list on error. The error message can be retrieved using the \&\f(CW\*(C`error\*(C'\fR method. .ie n .SS """servername""" .el .SS "\f(CWservername\fP" .IX Subsection "servername" .Vb 1 \& $file\->servername; .Ve .PP Returns the server name for this module \- if the protocol knows about a server, local files don't. .PP \&\s-1WARNING:\s0 The Padre \f(CW\*(C`path\*(C'\fR includes the server name in a protocol dependent syntax! .ie n .SS """size""" .el .SS "\f(CWsize\fP" .IX Subsection "size" .Vb 1 \& $file\->size; .Ve .PP Returns the file size in bytes or the empty list if the method was not implemented by the \f(CW\*(C`Padre::File\*(C'\fR subclass. .ie n .SS """stat""" .el .SS "\f(CWstat\fP" .IX Subsection "stat" .Vb 1 \& $file\->stat; .Ve .PP This emulates a stat call and returns the same values: .PP .Vb 10 \& 0 dev device number of file system \& 1 ino inode number \& 2 mode file mode (type and permissions) \& 3 nlink number of (hard) links to the file \& 4 uid numeric user ID of file\*(Aqs owner \& 5 gid numeric group ID of file\*(Aqs owner \& 6 rdev the device identifier (special files only) \& 7 size total size of file, in bytes \& 8 atime last access time in seconds since the epoch \& 9 mtime last modify time in seconds since the epoch \& 10 ctime inode change time in seconds since the epoch (*) \& 11 blksize preferred block size for file system I/O \& 12 blocks actual number of blocks allocated .Ve .PP A module should fill as many items as possible, but if you're thinking about using this method, always remember .IP "1." 4 Usually, you need only one or two of the items, request them directly. .IP "2." 4 Besides from local files, most of the values will not be accessible (resulting in empty lists/false returned). .IP "3." 4 On most protocols these values must be requested one-by-one, which is very expensive. .PP Please always consider using the function for the value you really need instead of using \f(CW\*(C`stat\*(C'\fR! .ie n .SS """uid""" .el .SS "\f(CWuid\fP" .IX Subsection "uid" .Vb 1 \& $file\->uid; .Ve .PP Returns the real user \s-1ID\s0 of the file owner. .PP This is usually not possible for non-local files, in these cases, the empty list is returned. .ie n .SS """write""" .el .SS "\f(CWwrite\fP" .IX Subsection "write" .Vb 2 \& $file\->write($Content); \& $file\->write($Content,$Coding); .Ve .PP Writes the given \f(CW$Content\fR to the file, if a encoding is given and the protocol allows encoding, it is respected. .PP Returns 1 on success. Returns 0 on failure. Returns the empty list if the function is not available on the protocol. .SH "INTERNAL METHODS" .IX Header "INTERNAL METHODS" .ie n .SS """_info""" .el .SS "\f(CW_info\fP" .IX Subsection "_info" .Vb 1 \& $file\->_info($message); .Ve .PP Shows \f(CW$message\fR to the user as an information. The output is guaranteed to be non-blocking and messages shown this way must be safe to be ignored by the user. .PP Doesn't return anything.