?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/README.tar
???????
home/.cpan/build/Path-Tiny-0.146-0/README 0000644 00000132444 15125143207 0013102 0 ustar 00 NAME Path::Tiny - File path utility VERSION version 0.146 SYNOPSIS use Path::Tiny; # Creating Path::Tiny objects my $dir = path("/tmp"); my $foo = path("foo.txt"); my $subdir = $dir->child("foo"); my $bar = $subdir->child("bar.txt"); # Stringifies as cleaned up path my $file = path("./foo.txt"); print $file; # "foo.txt" # Reading files my $guts = $file->slurp; $guts = $file->slurp_utf8; my @lines = $file->lines; @lines = $file->lines_utf8; my ($head) = $file->lines( {count => 1} ); my ($tail) = $file->lines( {count => -1} ); # Writing files $bar->spew( @data ); $bar->spew_utf8( @data ); # Reading directories for ( $dir->children ) { ... } my $iter = $dir->iterator; while ( my $next = $iter->() ) { ... } DESCRIPTION This module provides a small, fast utility for working with file paths. It is friendlier to use than File::Spec and provides easy access to functions from several other core file handling modules. It aims to be smaller and faster than many alternatives on CPAN, while helping people do many common things in consistent and less error-prone ways. Path::Tiny does not try to work for anything except Unix-like and Win32 platforms. Even then, it might break if you try something particularly obscure or tortuous. (Quick! What does this mean: "///../../..//./././a//b/.././c/././"? And how does it differ on Win32?) All paths are forced to have Unix-style forward slashes. Stringifying the object gives you back the path (after some clean up). File input/output methods "flock" handles before reading or writing, as appropriate (if supported by the platform and/or filesystem). The *_utf8 methods ("slurp_utf8", "lines_utf8", etc.) operate in raw mode. On Windows, that means they will not have CRLF translation from the ":crlf" IO layer. Installing Unicode::UTF8 0.58 or later will speed up *_utf8 situations in many cases and is highly recommended. Alternatively, installing PerlIO::utf8_strict 0.003 or later will be used in place of the default ":encoding(UTF-8)". This module depends heavily on PerlIO layers for correct operation and thus requires Perl 5.008001 or later. CONSTRUCTORS path $path = path("foo/bar"); $path = path("/tmp", "file.txt"); # list $path = path("."); # cwd Constructs a "Path::Tiny" object. It doesn't matter if you give a file or directory path. It's still up to you to call directory-like methods only on directories and file-like methods only on files. This function is exported automatically by default. The first argument must be defined and have non-zero length or an exception will be thrown. This prevents subtle, dangerous errors with code like "path( maybe_undef() )->remove_tree". DEPRECATED: If and only if the first character of the first argument to "path" is a tilde ('~'), then tilde replacement will be applied to the first path segment. A single tilde will be replaced with "glob('~')" and a tilde followed by a username will be replaced with output of "glob('~username')". No other method does tilde expansion on its arguments. See "Tilde expansion (deprecated)" for more. On Windows, if the path consists of a drive identifier without a path component ("C:" or "D:"), it will be expanded to the absolute path of the current directory on that volume using "Cwd::getdcwd()". If called with a single "Path::Tiny" argument, the original is returned unless the original is holding a temporary file or directory reference in which case a stringified copy is made. $path = path("foo/bar"); $temp = Path::Tiny->tempfile; $p2 = path($path); # like $p2 = $path $t2 = path($temp); # like $t2 = path( "$temp" ) This optimizes copies without proliferating references unexpectedly if a copy is made by code outside your control. Current API available since 0.017. new $path = Path::Tiny->new("foo/bar"); This is just like "path", but with method call overhead. (Why would you do that?) Current API available since 0.001. cwd $path = Path::Tiny->cwd; # path( Cwd::getcwd ) $path = cwd; # optional export Gives you the absolute path to the current directory as a "Path::Tiny" object. This is slightly faster than "path(".")->absolute". "cwd" may be exported on request and used as a function instead of as a method. Current API available since 0.018. rootdir $path = Path::Tiny->rootdir; # / $path = rootdir; # optional export Gives you "File::Spec->rootdir" as a "Path::Tiny" object if you're too picky for "path("/")". "rootdir" may be exported on request and used as a function instead of as a method. Current API available since 0.018. tempfile, tempdir $temp = Path::Tiny->tempfile( @options ); $temp = Path::Tiny->tempdir( @options ); $temp = $dirpath->tempfile( @options ); $temp = $dirpath->tempdir( @options ); $temp = tempfile( @options ); # optional export $temp = tempdir( @options ); # optional export "tempfile" passes the options to "File::Temp->new" and returns a "Path::Tiny" object with the file name. The "TMPDIR" option will be enabled by default, but you can override that by passing "TMPDIR => 0" along with the options. (If you use an absolute "TEMPLATE" option, you will want to disable "TMPDIR".) The resulting "File::Temp" object is cached. When the "Path::Tiny" object is destroyed, the "File::Temp" object will be as well. "File::Temp" annoyingly requires you to specify a custom template in slightly different ways depending on which function or method you call, but "Path::Tiny" lets you ignore that and can take either a leading template or a "TEMPLATE" option and does the right thing. $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok The tempfile path object will be normalized to have an absolute path, even if created in a relative directory using "DIR". If you want it to have the "realpath" instead, pass a leading options hash like this: $real_temp = tempfile({realpath => 1}, @options); "tempdir" is just like "tempfile", except it calls "File::Temp->newdir" instead. Both "tempfile" and "tempdir" may be exported on request and used as functions instead of as methods. The methods can be called on an instances representing a directory. In this case, the directory is used as the base to create the temporary file/directory, setting the "DIR" option in File::Temp. my $target_dir = path('/to/destination'); my $tempfile = $target_dir->tempfile('foobarXXXXXX'); $tempfile->spew('A lot of data...'); # not atomic $tempfile->move($target_dir->child('foobar')); # hopefully atomic In this case, any value set for option "DIR" is ignored. Note: for tempfiles, the filehandles from File::Temp are closed and not reused. This is not as secure as using File::Temp handles directly, but is less prone to deadlocks or access problems on some platforms. Think of what "Path::Tiny" gives you to be just a temporary file name that gets cleaned up. Note 2: if you don't want these cleaned up automatically when the object is destroyed, File::Temp requires different options for directories and files. Use "CLEANUP => 0" for directories and "UNLINK => 0" for files. Note 3: Don't lose the temporary object by chaining a method call instead of storing it: my $lost = tempdir()->child("foo"); # tempdir cleaned up right away Note 4: The cached object may be accessed with the "cached_temp" method. Keeping a reference to, or modifying the cached object may break the behavior documented above and is not supported. Use at your own risk. Current API available since 0.119. METHODS absolute $abs = path("foo/bar")->absolute; $abs = path("foo/bar")->absolute("/tmp"); Returns a new "Path::Tiny" object with an absolute path (or itself if already absolute). If no argument is given, the current directory is used as the absolute base path. If an argument is given, it will be converted to an absolute path (if it is not already) and used as the absolute base path. This will not resolve upward directories ("foo/../bar") unless "canonpath" in File::Spec would normally do so on your platform. If you need them resolved, you must call the more expensive "realpath" method instead. On Windows, an absolute path without a volume component will have it added based on the current drive. Current API available since 0.101. append, append_raw, append_utf8 path("foo.txt")->append(@data); path("foo.txt")->append(\@data); path("foo.txt")->append({binmode => ":raw"}, @data); path("foo.txt")->append_raw(@data); path("foo.txt")->append_utf8(@data); Appends data to a file. The file is locked with "flock" prior to writing and closed afterwards. An optional hash reference may be used to pass options. Valid options are: * "binmode": passed to "binmode()" on the handle used for writing. * "truncate": truncates the file after locking and before appending The "truncate" option is a way to replace the contents of a file in place, unlike "spew" which writes to a temporary file and then replaces the original (if it exists). "append_raw" is like "append" with a "binmode" of ":unix" for a fast, unbuffered, raw write. "append_utf8" is like "append" with an unbuffered "binmode" ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, an unbuffered, raw append will be done instead on the data encoded with "Unicode::UTF8". Current API available since 0.060. assert $path = path("foo.txt")->assert( sub { $_->exists } ); Returns the invocant after asserting that a code reference argument returns true. When the assertion code reference runs, it will have the invocant object in the $_ variable. If it returns false, an exception will be thrown. The assertion code reference may also throw its own exception. If no assertion is provided, the invocant is returned without error. Current API available since 0.062. basename $name = path("foo/bar.txt")->basename; # bar.txt $name = path("foo.txt")->basename('.txt'); # foo $name = path("foo.txt")->basename(qr/.txt/); # foo $name = path("foo.txt")->basename(@suffixes); Returns the file portion or last directory portion of a path. Given a list of suffixes as strings or regular expressions, any that match at the end of the file portion or last directory portion will be removed before the result is returned. Current API available since 0.054. canonpath $canonical = path("foo/bar")->canonpath; # foo\bar on Windows Returns a string with the canonical format of the path name for the platform. In particular, this means directory separators will be "\" on Windows. Current API available since 0.001. cached_temp Returns the cached "File::Temp" or "File::Temp::Dir" object if the "Path::Tiny" object was created with "/tempfile" or "/tempdir". If there is no such object, this method throws. WARNING: Keeping a reference to, or modifying the cached object may break the behavior documented for temporary files and directories created with "Path::Tiny" and is not supported. Use at your own risk. Current API available since 0.101. child $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" $file = path("/tmp")->child(@parts); Returns a new "Path::Tiny" object relative to the original. Works like "catfile" or "catdir" from File::Spec, but without caring about file or directories. WARNING: because the argument could contain ".." or refer to symlinks, there is no guarantee that the new path refers to an actual descendent of the original. If this is important to you, transform parent and child with "realpath" and check them with "subsumes". Current API available since 0.001. children @paths = path("/tmp")->children; @paths = path("/tmp")->children( qr/\.txt\z/ ); Returns a list of "Path::Tiny" objects for all files and directories within a directory. Excludes "." and ".." automatically. If an optional "qr//" argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching: @paths = path("/tmp")->children( qr/^foo/ ); # matches children like the glob foo* Current API available since 0.028. chmod path("foo.txt")->chmod(0777); path("foo.txt")->chmod("0755"); path("foo.txt")->chmod("go-w"); path("foo.txt")->chmod("a=r,u+wx"); Sets file or directory permissions. The argument can be a numeric mode, a octal string beginning with a "0" or a limited subset of the symbolic mode use by /bin/chmod. The symbolic mode must be a comma-delimited list of mode clauses. Clauses must match "qr/\A([augo]+)([=+-])([rwx]+)\z/", which defines "who", "op" and "perms" parameters for each clause. Unlike /bin/chmod, all three parameters are required for each clause, multiple ops are not allowed and permissions "stugoX" are not supported. (See File::chmod for more complex needs.) Current API available since 0.053. copy path("/tmp/foo.txt")->copy("/tmp/bar.txt"); Copies the current path to the given destination using File::Copy's "copy" function. Upon success, returns the "Path::Tiny" object for the newly copied file. Current API available since 0.070. digest $obj = path("/tmp/foo.txt")->digest; # SHA-256 $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); Returns a hexadecimal digest for a file. An optional hash reference of options may be given. The only option is "chunk_size". If "chunk_size" is given, that many bytes will be read at a time. If not provided, the entire file will be slurped into memory to compute the digest. Any subsequent arguments are passed to the constructor for Digest to select an algorithm. If no arguments are given, the default is SHA-256. Current API available since 0.056. dirname (deprecated) $name = path("/tmp/foo.txt")->dirname; # "/tmp/" Returns the directory portion you would get from calling "File::Spec->splitpath( $path->stringify )" or "." for a path without a parent directory portion. Because File::Spec is inconsistent, the result might or might not have a trailing slash. Because of this, this method is deprecated. A better, more consistently approach is likely "$path->parent->stringify", which will not have a trailing slash except for a root directory. Deprecated in 0.056. edit, edit_raw, edit_utf8 path("foo.txt")->edit( \&callback, $options ); path("foo.txt")->edit_utf8( \&callback ); path("foo.txt")->edit_raw( \&callback ); These are convenience methods that allow "editing" a file using a single callback argument. They slurp the file using "slurp", place the contents inside a localized $_ variable, call the callback function (without arguments), and then write $_ (presumably mutated) back to the file with "spew". An optional hash reference may be used to pass options. The only option is "binmode", which is passed to "slurp" and "spew". "edit_utf8" and "edit_raw" act like their respective "slurp_*" and "spew_*" methods. Current API available since 0.077. edit_lines, edit_lines_utf8, edit_lines_raw path("foo.txt")->edit_lines( \&callback, $options ); path("foo.txt")->edit_lines_utf8( \&callback ); path("foo.txt")->edit_lines_raw( \&callback ); These are convenience methods that allow "editing" a file's lines using a single callback argument. They iterate over the file: for each line, the line is put into a localized $_ variable, the callback function is executed (without arguments) and then $_ is written to a temporary file. When iteration is finished, the temporary file is atomically renamed over the original. An optional hash reference may be used to pass options. The only option is "binmode", which is passed to the method that open handles for reading and writing. "edit_lines_raw" is like "edit_lines" with a buffered "binmode" of ":raw". "edit_lines_utf8" is like "edit_lines" with a buffered "binmode" ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). Current API available since 0.077. exists, is_file, is_dir if ( path("/tmp")->exists ) { ... } # -e if ( path("/tmp")->is_dir ) { ... } # -d if ( path("/tmp")->is_file ) { ... } # -e && ! -d Implements file test operations, this means the file or directory actually has to exist on the filesystem. Until then, it's just a path. Note: "is_file" is not "-f" because "-f" is not the opposite of "-d". "-f" means "plain file", excluding symlinks, devices, etc. that often can be read just like files. Use "-f" instead if you really mean to check for a plain file. Current API available since 0.053. filehandle $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); Returns an open file handle. The $mode argument must be a Perl-style read/write mode string ("<" ,">", ">>", etc.). If a $binmode is given, it is set during the "open" call. An optional hash reference may be used to pass options. The "locked" option governs file locking; if true, handles opened for writing, appending or read-write are locked with "LOCK_EX"; otherwise, they are locked with "LOCK_SH". When using "locked", ">" or "+>" modes will delay truncation until after the lock is acquired. The "exclusive" option causes the open() call to fail if the file already exists. This corresponds to the O_EXCL flag to sysopen / open(2). "exclusive" implies "locked" and will set it for you if you forget it. See "openr", "openw", "openrw", and "opena" for sugar. Current API available since 0.066. has_same_bytes if ( path("foo.txt")->has_same_bytes("bar.txt") ) { # ... } This method returns true if both the invocant and the argument can be opened as file handles and the handles contain the same bytes. It returns false if their contents differ. If either can't be opened as a file (e.g. a directory or non-existent file), the method throws an exception. If both can be opened and both have the same "realpath", the method returns true without scanning any data. Current API available since 0.125. is_absolute, is_relative if ( path("/tmp")->is_absolute ) { ... } if ( path("/tmp")->is_relative ) { ... } Booleans for whether the path appears absolute or relative. Current API available since 0.001. is_rootdir while ( ! $path->is_rootdir ) { $path = $path->parent; ... } Boolean for whether the path is the root directory of the volume. I.e. the "dirname" is "q[/]" and the "basename" is "q[]". This works even on "MSWin32" with drives and UNC volumes: path("C:/")->is_rootdir; # true path("//server/share/")->is_rootdir; #true Current API available since 0.038. iterator $iter = path("/tmp")->iterator( \%options ); Returns a code reference that walks a directory lazily. Each invocation returns a "Path::Tiny" object or undef when the iterator is exhausted. $iter = path("/tmp")->iterator; while ( $path = $iter->() ) { ... } The current and parent directory entries ("." and "..") will not be included. If the "recurse" option is true, the iterator will walk the directory recursively, breadth-first. If the "follow_symlinks" option is also true, directory links will be followed recursively. There is no protection against loops when following links. If a directory is not readable, it will not be followed. The default is the same as: $iter = path("/tmp")->iterator( { recurse => 0, follow_symlinks => 0, } ); For a more powerful, recursive iterator with built-in loop avoidance, see Path::Iterator::Rule. See also "visit". Current API available since 0.016. lines, lines_raw, lines_utf8 @contents = path("/tmp/foo.txt")->lines; @contents = path("/tmp/foo.txt")->lines(\%options); @contents = path("/tmp/foo.txt")->lines_raw; @contents = path("/tmp/foo.txt")->lines_utf8; @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); Returns a list of lines from a file. Optionally takes a hash-reference of options. Valid options are "binmode", "count" and "chomp". If "binmode" is provided, it will be set on the handle prior to reading. If a positive "count" is provided, that many lines will be returned from the start of the file. If a negative "count" is provided, the entire file will be read, but only "abs(count)" will be kept and returned. If "abs(count)" exceeds the number of lines in the file, all lines will be returned. If "chomp" is set, any end-of-line character sequences ("CR", "CRLF", or "LF") will be removed from the lines returned. Because the return is a list, "lines" in scalar context will return the number of lines (and throw away the data). $number_of_lines = path("/tmp/foo.txt")->lines; "lines_raw" is like "lines" with a "binmode" of ":raw". We use ":raw" instead of ":unix" so PerlIO buffering can manage reading by line. "lines_utf8" is like "lines" with a "binmode" of ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the lines will be split. This is actually faster than relying on IO layers, though a bit memory intensive. If memory use is a concern, consider "openr_utf8" and iterating directly on the handle. Current API available since 0.065. mkdir path("foo/bar/baz")->mkdir; path("foo/bar/baz")->mkdir( \%options ); Like calling "make_path" from File::Path. An optional hash reference is passed through to "make_path". Errors will be trapped and an exception thrown. Returns the the path object to facilitate chaining. NOTE: unlike Perl's builtin "mkdir", this will create intermediate paths similar to the Unix "mkdir -p" command. It will not error if applied to an existing directory. Current API available since 0.125. mkpath (deprecated) Like calling "mkdir", but returns the list of directories created or an empty list if the directories already exist, just like "make_path". Deprecated in 0.125. move path("foo.txt")->move("bar.txt"); Moves the current path to the given destination using File::Copy's "move" function. Upon success, returns the "Path::Tiny" object for the newly moved file. If the destination already exists and is a directory, and the source is not a directory, then the source file will be renamed into the directory specified by the destination. If possible, move() will simply rename the file. Otherwise, it copies the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. Current API available since 0.124. Prior versions used Perl's -built-in (and less robust) rename function and did not return an object. openr, openw, openrw, opena $fh = path("foo.txt")->openr($binmode); # read $fh = path("foo.txt")->openr_raw; $fh = path("foo.txt")->openr_utf8; $fh = path("foo.txt")->openw($binmode); # write $fh = path("foo.txt")->openw_raw; $fh = path("foo.txt")->openw_utf8; $fh = path("foo.txt")->opena($binmode); # append $fh = path("foo.txt")->opena_raw; $fh = path("foo.txt")->opena_utf8; $fh = path("foo.txt")->openrw($binmode); # read/write $fh = path("foo.txt")->openrw_raw; $fh = path("foo.txt")->openrw_utf8; Returns a file handle opened in the specified mode. The "openr" style methods take a single "binmode" argument. All of the "open*" methods have "open*_raw" and "open*_utf8" equivalents that use buffered I/O layers ":raw" and ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). An optional hash reference may be used to pass options. The only option is "locked". If true, handles opened for writing, appending or read-write are locked with "LOCK_EX"; otherwise, they are locked for "LOCK_SH". $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); See "filehandle" for more on locking. Current API available since 0.011. parent $parent = path("foo/bar/baz")->parent; # foo/bar $parent = path("foo/wibble.txt")->parent; # foo $parent = path("foo/bar/baz")->parent(2); # foo Returns a "Path::Tiny" object corresponding to the parent directory of the original directory or file. An optional positive integer argument is the number of parent directories upwards to return. "parent" by itself is equivalent to parent(1). Current API available since 0.014. realpath $real = path("/baz/foo/../bar")->realpath; $real = path("foo/../bar")->realpath; Returns a new "Path::Tiny" object with all symbolic links and upward directory parts resolved using Cwd's "realpath". Compared to "absolute", this is more expensive as it must actually consult the filesystem. If the parent path can't be resolved (e.g. if it includes directories that don't exist), an exception will be thrown: $real = path("doesnt_exist/foo")->realpath; # dies However, if the parent path exists and only the last component (e.g. filename) doesn't exist, the realpath will be the realpath of the parent plus the non-existent last component: $real = path("./aasdlfasdlf")->realpath; # works The underlying Cwd module usually worked this way on Unix, but died on Windows (and some Unixes) if the full path didn't exist. As of version 0.064, it's safe to use anywhere. Current API available since 0.001. relative $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar Returns a "Path::Tiny" object with a path relative to a new base path given as an argument. If no argument is given, the current directory will be used as the new base path. If either path is already relative, it will be made absolute based on the current directly before determining the new relative path. The algorithm is roughly as follows: * If the original and new base path are on different volumes, an exception will be thrown. * If the original and new base are identical, the relative path is ".". * If the new base subsumes the original, the relative path is the original path with the new base chopped off the front * If the new base does not subsume the original, a common prefix path is determined (possibly the root directory) and the relative path will consist of updirs ("..") to reach the common prefix, followed by the original path less the common prefix. Unlike "File::Spec::abs2rel", in the last case above, the calculation based on a common prefix takes into account symlinks that could affect the updir process. Given an original path "/A/B" and a new base "/A/C", (where "A", "B" and "C" could each have multiple path components): * Symlinks in "A" don't change the result unless the last component of A is a symlink and the first component of "C" is an updir. * Symlinks in "B" don't change the result and will exist in the result as given. * Symlinks and updirs in "C" must be resolved to actual paths, taking into account the possibility that not all path components might exist on the filesystem. Current API available since 0.001. New algorithm (that accounts for symlinks) available since 0.079. remove path("foo.txt")->remove; This is just like "unlink", except for its error handling: if the path does not exist, it returns false; if deleting the file fails, it throws an exception. Current API available since 0.012. remove_tree # directory path("foo/bar/baz")->remove_tree; path("foo/bar/baz")->remove_tree( \%options ); path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove Like calling "remove_tree" from File::Path, but defaults to "safe" mode. An optional hash reference is passed through to "remove_tree". Errors will be trapped and an exception thrown. Returns the number of directories deleted, just like "remove_tree". If you want to remove a directory only if it is empty, use the built-in "rmdir" function instead. rmdir path("foo/bar/baz/"); Current API available since 0.013. sibling $foo = path("/tmp/foo.txt"); $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt Returns a new "Path::Tiny" object relative to the parent of the original. This is slightly more efficient than "$path->parent->child(...)". Current API available since 0.058. size, size_human my $p = path("foo"); # with size 1025 bytes $p->size; # "1025" $p->size_human; # "1.1 K" $p->size_human( {format => "iec"} ); # "1.1 KiB" Returns the size of a file. The "size" method is just a wrapper around "-s". The "size_human" method provides a human-readable string similar to "ls -lh". Like "ls", it rounds upwards and provides one decimal place for single-digit sizes and no decimal places for larger sizes. The only available option is "format", which has three valid values: * 'ls' (the default): base-2 sizes, with "ls" style single-letter suffixes (K, M, etc.) * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) If "-s" would return "undef", "size_human" returns the empty string. Current API available since 0.122. slurp, slurp_raw, slurp_utf8 $data = path("foo.txt")->slurp; $data = path("foo.txt")->slurp( {binmode => ":raw"} ); $data = path("foo.txt")->slurp_raw; $data = path("foo.txt")->slurp_utf8; Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is "binmode", which is passed to "binmode()" on the handle used for reading. "slurp_raw" is like "slurp" with a "binmode" of ":unix" for a fast, unbuffered, raw read. "slurp_utf8" is like "slurp" with a "binmode" of ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a unbuffered, raw slurp will be done instead and the result decoded with "Unicode::UTF8". This is just as strict and is roughly an order of magnitude faster than using ":encoding(UTF-8)". Note: "slurp" and friends lock the filehandle before slurping. If you plan to slurp from a file created with File::Temp, be sure to close other handles or open without locking to avoid a deadlock: my $tempfile = File::Temp->new(EXLOCK => 0); my $guts = path($tempfile)->slurp; Current API available since 0.004. spew, spew_raw, spew_utf8 path("foo.txt")->spew(@data); path("foo.txt")->spew(\@data); path("foo.txt")->spew({binmode => ":raw"}, @data); path("foo.txt")->spew_raw(@data); path("foo.txt")->spew_utf8(@data); Writes data to a file atomically. The file is written to a temporary file in the same directory, then renamed over the original. An optional hash reference may be used to pass options. The only option is "binmode", which is passed to "binmode()" on the handle used for writing. "spew_raw" is like "spew" with a "binmode" of ":unix" for a fast, unbuffered, raw write. "spew_utf8" is like "spew" with a "binmode" of ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered spew will be done instead on the data encoded with "Unicode::UTF8". NOTE: because the file is written to a temporary file and then renamed, the new file will wind up with permissions based on your current umask. This is a feature to protect you from a race condition that would otherwise give different permissions than you might expect. If you really want to keep the original mode flags, use "append" with the "truncate" option. Current API available since 0.011. stat, lstat $stat = path("foo.txt")->stat; $stat = path("/some/symlink")->lstat; Like calling "stat" or "lstat" from File::stat. Current API available since 0.001. stringify $path = path("foo.txt"); say $path->stringify; # same as "$path" Returns a string representation of the path. Unlike "canonpath", this method returns the path standardized with Unix-style "/" directory separators. Current API available since 0.001. subsumes path("foo/bar")->subsumes("foo/bar/baz"); # true path("/foo/bar")->subsumes("/foo/baz"); # false Returns true if the first path is a prefix of the second path at a directory boundary. This does not resolve parent directory entries ("..") or symlinks: path("foo/bar")->subsumes("foo/bar/../baz"); # true If such things are important to you, ensure that both paths are resolved to the filesystem with "realpath": my $p1 = path("foo/bar")->realpath; my $p2 = path("foo/bar/../baz")->realpath; if ( $p1->subsumes($p2) ) { ... } Current API available since 0.048. touch path("foo.txt")->touch; path("foo.txt")->touch($epoch_secs); Like the Unix "touch" utility. Creates the file if it doesn't exist, or else changes the modification and access times to the current time. If the first argument is the epoch seconds then it will be used. Returns the path object so it can be easily chained with other methods: # won't die if foo.txt doesn't exist $content = path("foo.txt")->touch->slurp; Current API available since 0.015. touchpath path("bar/baz/foo.txt")->touchpath; Combines "mkdir" and "touch". Creates the parent directory if it doesn't exist, before touching the file. Returns the path object like "touch" does. If you need to pass options, use "mkdir" and "touch" separately: path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); Current API available since 0.022. visit path("/tmp")->visit( \&callback, \%options ); Executes a callback for each child of a directory. It returns a hash reference with any state accumulated during iteration. The options are the same as for "iterator" (which it uses internally): "recurse" and "follow_symlinks". Both default to false. The callback function will receive a "Path::Tiny" object as the first argument and a hash reference to accumulate state as the second argument. For example: # collect files sizes my $sizes = path("/tmp")->visit( sub { my ($path, $state) = @_; return if $path->is_dir; $state->{$path} = -s $path; }, { recurse => 1 } ); For convenience, the "Path::Tiny" object will also be locally aliased as the $_ global variable: # print paths matching /foo/ path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); If the callback returns a reference to a false scalar value, iteration will terminate. This is not the same as "pruning" a directory search; this just stops all iteration and returns the state hash reference. # find up to 10 files larger than 100K my $files = path("/tmp")->visit( sub { my ($path, $state) = @_; $state->{$path}++ if -s $path > 102400 return \0 if keys %$state == 10; }, { recurse => 1 } ); If you want more flexible iteration, use a module like Path::Iterator::Rule. Current API available since 0.062. volume $vol = path("/tmp/foo.txt")->volume; # "" $vol = path("C:/tmp/foo.txt")->volume; # "C:" Returns the volume portion of the path. This is equivalent to what File::Spec would give from "splitpath" and thus usually is the empty string on Unix-like operating systems or the drive letter for an absolute path on "MSWin32". Current API available since 0.001. EXCEPTION HANDLING Simple usage errors will generally croak. Failures of underlying Perl functions will be thrown as exceptions in the class "Path::Tiny::Error". A "Path::Tiny::Error" object will be a hash reference with the following fields: * "op" — a description of the operation, usually function call and any extra info * "file" — the file or directory relating to the error * "err" — hold $! at the time the error was thrown * "msg" — a string combining the above data and a Carp-like short stack trace Exception objects will stringify as the "msg" field. ENVIRONMENT PERL_PATH_TINY_NO_FLOCK If the environment variable "PERL_PATH_TINY_NO_FLOCK" is set to a true value then flock will NOT be used when accessing files (this is not recommended). CAVEATS Subclassing not supported For speed, this class is implemented as an array based object and uses many direct function calls internally. You must not subclass it and expect things to work properly. Tilde expansion (deprecated) Tilde expansion was a nice idea, but it can't easily be applied consistently across the entire API. This was a source of bugs and confusion for users. Therefore, it is deprecated and its use is discouraged. Limitations to the existing, legacy behavior follow. Tilde expansion will only occur if the first argument to "path" begins with a tilde. No other method does tilde expansion on its arguments. If you want tilde expansion on arguments, you must explicitly wrap them in a call to "path". path( "~/foo.txt" )->copy( path( "~/bar.txt" ) ); If you need a literal leading tilde, use "path("./~whatever")" so that the argument to "path" doesn't start with a tilde, but the path still resolves to the current directory. Behaviour of tilde expansion with a username for non-existent users depends on the output of "glob" on the system. File locking If flock is not supported on a platform, it will not be used, even if locking is requested. In situations where a platform normally would support locking, but the flock fails due to a filesystem limitation, Path::Tiny has some heuristics to detect this and will warn once and continue in an unsafe mode. If you want this failure to be fatal, you can fatalize the 'flock' warnings category: use warnings FATAL => 'flock'; See additional caveats below. NFS and BSD On BSD, Perl's flock implementation may not work to lock files on an NFS filesystem. If detected, this situation will warn once, as described above. Lustre The Lustre filesystem does not support flock. If detected, this situation will warn once, as described above. AIX and locking AIX requires a write handle for locking. Therefore, calls that normally open a read handle and take a shared lock instead will open a read-write handle and take an exclusive lock. If the user does not have write permission, no lock will be used. utf8 vs UTF-8 All the *_utf8 methods by default use ":encoding(UTF-8)" -- either as ":unix:encoding(UTF-8)" (unbuffered, for whole file operations) or ":raw:encoding(UTF-8)" (buffered, for line-by-line operations). These are strict against the Unicode spec and disallows illegal Unicode codepoints or UTF-8 sequences. Unfortunately, ":encoding(UTF-8)" is very, very slow. If you install Unicode::UTF8 0.58 or later, that module will be used by some *_utf8 methods to encode or decode data after a raw, binary input/output operation, which is much faster. Alternatively, if you install PerlIO::utf8_strict, that will be used instead of ":encoding(UTF-8)" and is also very fast. If you need the performance and can accept the security risk, "slurp({binmode => ":unix:utf8"})" will be faster than ":unix:encoding(UTF-8)" (but not as fast as "Unicode::UTF8"). Note that the *_utf8 methods read in raw mode. There is no CRLF translation on Windows. If you must have CRLF translation, use the regular input/output methods with an appropriate binmode: $path->spew_utf8($data); # raw $path->spew({binmode => ":encoding(UTF-8)"}, $data; # LF -> CRLF Default IO layers and the open pragma If you have Perl 5.10 or later, file input/output methods ("slurp", "spew", etc.) and high-level handle opening methods ( "filehandle", "openr", "openw", etc. ) respect default encodings set by the "-C" switch or lexical open settings of the caller. For UTF-8, this is almost certainly slower than using the dedicated "_utf8" methods if you have Unicode::UTF8 or PerlIP::utf8_strict. TYPE CONSTRAINTS AND COERCION A standard MooseX::Types library is available at MooseX::Types::Path::Tiny. A Type::Tiny equivalent is available as Types::Path::Tiny. SEE ALSO These are other file/path utilities, which may offer a different feature set than "Path::Tiny". * File::chmod * File::Fu * IO::All * Path::Class These iterators may be slightly faster than the recursive iterator in "Path::Tiny": * Path::Iterator::Rule * File::Next There are probably comparable, non-Tiny tools. Let me know if you want me to add a module to the list. This module was featured in the 2013 Perl Advent Calendar <http://www.perladvent.org/2013/2013-12-18.html>. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Path-Tiny/issues>. You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/dagolden/Path-Tiny> git clone https://github.com/dagolden/Path-Tiny.git AUTHOR David Golden <dagolden@cpan.org> CONTRIBUTORS * Alex Efros <powerman@powerman.name> * Aristotle Pagaltzis <pagaltzis@gmx.de> * Chris Williams <bingos@cpan.org> * Dan Book <grinnz@grinnz.com> * Dave Rolsky <autarch@urth.org> * David Steinbrunner <dsteinbrunner@pobox.com> * Doug Bell <madcityzen@gmail.com> * Elvin Aslanov <rwp.primary@gmail.com> * Flavio Poletti <flavio@polettix.it> * Gabor Szabo <szabgab@cpan.org> * Gabriel Andrade <gabiruh@gmail.com> * George Hartzell <hartzell@cpan.org> * Geraud Continsouzas <geraud@scsi.nc> * Goro Fuji <gfuji@cpan.org> * Graham Knop <haarg@haarg.org> * Graham Ollis <plicease@cpan.org> * Ian Sillitoe <ian@sillit.com> * James Hunt <james@niftylogic.com> * John Karr <brainbuz@brainbuz.org> * Karen Etheridge <ether@cpan.org> * Mark Ellis <mark.ellis@cartridgesave.co.uk> * Martin H. Sluka <fany@cpan.org> * Martin Kjeldsen <mk@bluepipe.dk> * Mary Ehlers <regina.verb.ae@gmail.com> * Michael G. Schwern <mschwern@cpan.org> * Nicolas R <nicolas@atoomic.org> * Nicolas Rochelemagne <rochelemagne@cpanel.net> * Nigel Gregoire <nigelgregoire@gmail.com> * Philippe Bruhat (BooK) <book@cpan.org> * regina-verbae <regina-verbae@users.noreply.github.com> * Roy Ivy III <rivy@cpan.org> * Shlomi Fish <shlomif@shlomifish.org> * Smylers <Smylers@stripey.com> * Tatsuhiko Miyagawa <miyagawa@bulknews.net> * Toby Inkster <tobyink@cpan.org> * Yanick Champoux <yanick@babyl.dyndns.org> * 김도형 - Keedi Kim <keedi@cpan.org> COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 home/.cpan/build/Storable-3.25-0/README 0000644 00000011416 15125143244 0012753 0 ustar 00 Storable 3.05c Copyright (c) 1995-2000, Raphael Manfredi Copyright (c) 2001-2004, Larry Wall Copyright (c) 2016,2017 cPanel Inc ------------------------------------------------------------------------ This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Perl 5 License schemes for more details. ------------------------------------------------------------------------ +======================================================================= | Storable is distributed as a module, but is also part of the official | Perl core distribution, as of perl 5.8. | Maintenance is partially done by the perl5-porters, and for cperl by cPanel. | We thank Raphael Manfredi for providing us with this very useful module. +======================================================================= The Storable extension brings persistence to your data. You may recursively store to disk any data structure, no matter how complex and circular it is, provided it contains only SCALAR, ARRAY, HASH (possibly tied) and references (possibly blessed) to those items. At a later stage, or in another program, you may retrieve data from the stored file and recreate the same hiearchy in memory. If you had blessed references, the retrieved references are blessed into the same package, so you must make sure you have access to the same perl class than the one used to create the relevant objects. There is also a dclone() routine which performs an optimized mirroring of any data structure, preserving its topology. Objects (blessed references) may also redefine the way storage and retrieval is performed, and/or what deep cloning should do on those objects. To compile this extension, run: perl Makefile.PL [PERL_SRC=...where you put perl sources...] make make install There is an embedded POD manual page in Storable.pm. Storable was written by Raphael Manfredi <Raphael_Manfredi@pobox.com> Maintenance is now done by cperl, https://github.com/rurban/Storable/ Note that p5p still ships an old broken version, without stack overflow protection and large object support. As long as you don't store overlarge objects, they are compatible. Please e-mail us with problems, bug fixes, comments and complaints, although if you have complements you should send them to Raphael. Please don't e-mail Raphael with problems, as he no longer works on Storable, and your message will be delayed while he forwards it to us. ------------------------------------------------------------------------ Thanks to (in chronological order): Jarkko Hietaniemi <jhi@iki.fi> Ulrich Pfeifer <pfeifer@charly.informatik.uni-dortmund.de> Benjamin A. Holzman <bholzman@earthlink.net> Andrew Ford <A.Ford@ford-mason.co.uk> Gisle Aas <gisle@aas.no> Jeff Gresham <gresham_jeffrey@jpmorgan.com> Murray Nesbitt <murray@activestate.com> Albert N. Micheev <Albert.N.Micheev@f80.n5049.z2.fidonet.org> Marc Lehmann <pcg@opengroup.org> Justin Banks <justinb@wamnet.com> Jarkko Hietaniemi <jhi@iki.fi> (AGAIN, as perl 5.7.0 Pumpkin!) Todd Rinaldo <toddr@cpanel.net> and JD Lightsey <jd@cpanel.net> for optional disabling tie and bless for increased security. Reini Urban <rurban@cpanel.net> for the 3.0x >2G support and rewrite JD Lightsey <jd@cpanel.net> for their contributions. A Japanese translation of this man page is available at the Japanized Perl Resources Project <https://sourceforge.jp/projects/perldocjp/>. ------------------------------------------------------------------------ The perl5-porters would like to thank Raphael Manfredi <Raphael_Manfredi@pobox.com> According to the perl5.8 Changes file, the following people have helped bring you this Storable release: Abhijit Menon-Sen <ams@wiw.org> Andreas J. Koenig <andreas.koenig@anima.de> Archer Sully <archer@meer.net> Craig A. Berry <craig.berry@psinetcs.com> Dan Kogai <dankogai@dan.co.jp> Doug MacEachern <dougm@covalent.net> Gurusamy Sarathy <gsar@ActiveState.com> H.Merijn Brand <h.m.brand@xs4all.nl> Jarkko Hietaniemi <jhi@iki.fi> Mark Bixby Michael Stevens <michael@etla.org> Mike Guy <mjtg@cam.ac.uk> Nicholas Clark <nick@unfortu.net> Peter J. Farley III <pjfarley@banet.net> Peter Prymmer <pvhp@forte.com> Philip Newton <pne@cpan.org> Raphael Manfredi <Raphael_Manfredi@pobox.com> Robin Barker <rmb1@cise.npl.co.uk> Radu Greab <radu@netsoft.ro> Tim Bunce <Tim.Bunce@pobox.com> VMSperlers Yitzchak Scott-Thoennes <sthoenna@efn.org> home/.cpan/build/JSON-4.10-0/README 0000644 00000131622 15125143260 0011744 0 ustar 00 NAME JSON - JSON (JavaScript Object Notation) encoder/decoder SYNOPSIS use JSON; # imports encode_json, decode_json, to_json and from_json. # simple and fast interfaces (expect/generate UTF-8) $utf8_encoded_json_text = encode_json $perl_hash_or_arrayref; $perl_hash_or_arrayref = decode_json $utf8_encoded_json_text; # OO-interface $json = JSON->new->allow_nonref; $json_text = $json->encode( $perl_scalar ); $perl_scalar = $json->decode( $json_text ); $pretty_printed = $json->pretty->encode( $perl_scalar ); # pretty-printing VERSION 2.93 DESCRIPTION This module is a thin wrapper for JSON::XS-compatible modules with a few additional features. All the backend modules convert a Perl data structure to a JSON text as of RFC4627 (which we know is obsolete but we still stick to; see below for an option to support part of RFC7159) and vice versa. This module uses JSON::XS by default, and when JSON::XS is not available, this module falls back on JSON::PP, which is in the Perl core since 5.14. If JSON::PP is not available either, this module then falls back on JSON::backportPP (which is actually JSON::PP in a different .pm file) bundled in the same distribution as this module. You can also explicitly specify to use Cpanel::JSON::XS, a fork of JSON::XS by Reini Urban. All these backend modules have slight incompatibilities between them, including extra features that other modules don't support, but as long as you use only common features (most important ones are described below), migration from backend to backend should be reasonably easy. For details, see each backend module you use. CHOOSING BACKEND This module respects an environmental variable called "PERL_JSON_BACKEND" when it decides a backend module to use. If this environmental variable is not set, it tries to load JSON::XS, and if JSON::XS is not available, it falls back on JSON::PP, and then JSON::backportPP if JSON::PP is not available either. If you always don't want it to fall back on pure perl modules, set the variable like this ("export" may be "setenv", "set" and the likes, depending on your environment): > export PERL_JSON_BACKEND=JSON::XS If you prefer Cpanel::JSON::XS to JSON::XS, then: > export PERL_JSON_BACKEND=Cpanel::JSON::XS,JSON::XS,JSON::PP You may also want to set this variable at the top of your test files, in order not to be bothered with incompatibilities between backends (you need to wrap this in "BEGIN", and set before actually "use"-ing JSON module, as it decides its backend as soon as it's loaded): BEGIN { $ENV{PERL_JSON_BACKEND}='JSON::backportPP'; } use JSON; USING OPTIONAL FEATURES There are a few options you can set when you "use" this module: -support_by_pp BEGIN { $ENV{PERL_JSON_BACKEND} = 'JSON::XS' } use JSON -support_by_pp; my $json = JSON->new; # escape_slash is for JSON::PP only. $json->allow_nonref->escape_slash->encode("/"); With this option, this module loads its pure perl backend along with its XS backend (if available), and lets the XS backend to watch if you set a flag only JSON::PP supports. When you do, the internal JSON::XS object is replaced with a newly created JSON::PP object with the setting copied from the XS object, so that you can use JSON::PP flags (and its slower "decode"/"encode" methods) from then on. In other words, this is not something that allows you to hook JSON::XS to change its behavior while keeping its speed. JSON::XS and JSON::PP objects are quite different (JSON::XS object is a blessed scalar reference, while JSON::PP object is a blessed hash reference), and can't share their internals. To avoid needless overhead (by copying settings), you are advised not to use this option and just to use JSON::PP explicitly when you need JSON::PP features. -convert_blessed_universally use JSON -convert_blessed_universally; my $json = JSON->new->allow_nonref->convert_blessed; my $object = bless {foo => 'bar'}, 'Foo'; $json->encode($object); # => {"foo":"bar"} JSON::XS-compatible backend modules don't encode blessed objects by default (except for their boolean values, which are typically blessed JSON::PP::Boolean objects). If you need to encode a data structure that may contain objects, you usually need to look into the structure and replace objects with alternative non-blessed values, or enable "convert_blessed" and provide a "TO_JSON" method for each object's (base) class that may be found in the structure, in order to let the methods replace the objects with whatever scalar values the methods return. If you need to serialise data structures that may contain arbitrary objects, it's probably better to use other serialisers (such as Sereal or Storable for example), but if you do want to use this module for that purpose, "-convert_blessed_universally" option may help, which tweaks "encode" method of the backend to install "UNIVERSAL::TO_JSON" method (locally) before encoding, so that all the objects that don't have their own "TO_JSON" method can fall back on the method in the "UNIVERSAL" namespace. Note that you still need to enable "convert_blessed" flag to actually encode objects in a data structure, and "UNIVERSAL::TO_JSON" method installed by this option only converts blessed hash/array references into their unblessed clone (including private keys/values that are not supposed to be exposed). Other blessed references will be converted into null. This feature is experimental and may be removed in the future. -no_export When you don't want to import functional interfaces from a module, you usually supply "()" to its "use" statement. use JSON (); # no functional interfaces If you don't want to import functional interfaces, but you also want to use any of the above options, add "-no_export" to the option list. # no functional interfaces, while JSON::PP support is enabled. use JSON -support_by_pp, -no_export; FUNCTIONAL INTERFACE This section is taken from JSON::XS. "encode_json" and "decode_json" are exported by default. This module also exports "to_json" and "from_json" for backward compatibility. These are slower, and may expect/generate different stuff from what "encode_json" and "decode_json" do, depending on their options. It's better just to use Object-Oriented interfaces than using these two functions. encode_json $json_text = encode_json $perl_scalar Converts the given Perl data structure to a UTF-8 encoded, binary string (that is, the string contains octets only). Croaks on error. This function call is functionally identical to: $json_text = JSON->new->utf8->encode($perl_scalar) Except being faster. decode_json $perl_scalar = decode_json $json_text The opposite of "encode_json": expects an UTF-8 (binary) string and tries to parse that as an UTF-8 encoded JSON text, returning the resulting reference. Croaks on error. This function call is functionally identical to: $perl_scalar = JSON->new->utf8->decode($json_text) Except being faster. to_json $json_text = to_json($perl_scalar[, $optional_hashref]) Converts the given Perl data structure to a Unicode string by default. Croaks on error. Basically, this function call is functionally identical to: $json_text = JSON->new->encode($perl_scalar) Except being slower. You can pass an optional hash reference to modify its behavior, but that may change what "to_json" expects/generates (see "ENCODING/CODESET FLAG NOTES" for details). $json_text = to_json($perl_scalar, {utf8 => 1, pretty => 1}) # => JSON->new->utf8(1)->pretty(1)->encode($perl_scalar) from_json $perl_scalar = from_json($json_text[, $optional_hashref]) The opposite of "to_json": expects a Unicode string and tries to parse it, returning the resulting reference. Croaks on error. Basically, this function call is functionally identical to: $perl_scalar = JSON->new->decode($json_text) You can pass an optional hash reference to modify its behavior, but that may change what "from_json" expects/generates (see "ENCODING/CODESET FLAG NOTES" for details). $perl_scalar = from_json($json_text, {utf8 => 1}) # => JSON->new->utf8(1)->decode($json_text) JSON::is_bool $is_boolean = JSON::is_bool($scalar) Returns true if the passed scalar represents either JSON::true or JSON::false, two constants that act like 1 and 0 respectively and are also used to represent JSON "true" and "false" in Perl strings. See MAPPING, below, for more information on how JSON values are mapped to Perl. COMMON OBJECT-ORIENTED INTERFACE This section is also taken from JSON::XS. The object oriented interface lets you configure your own encoding or decoding style, within the limits of supported formats. new $json = JSON->new Creates a new JSON::XS-compatible backend object that can be used to de/encode JSON strings. All boolean flags described below are by default *disabled*. The mutators for flags all return the backend object again and thus calls can be chained: my $json = JSON->new->utf8->space_after->encode({a => [1,2]}) => {"a": [1, 2]} ascii $json = $json->ascii([$enable]) $enabled = $json->get_ascii If $enable is true (or missing), then the "encode" method will not generate characters outside the code range 0..127 (which is ASCII). Any Unicode characters outside that range will be escaped using either a single \uXXXX (BMP characters) or a double \uHHHH\uLLLLL escape sequence, as per RFC4627. The resulting encoded JSON text can be treated as a native Unicode string, an ascii-encoded, latin1-encoded or UTF-8 encoded string, or any other superset of ASCII. If $enable is false, then the "encode" method will not escape Unicode characters unless required by the JSON syntax or other flags. This results in a faster and more compact format. See also the section *ENCODING/CODESET FLAG NOTES* later in this document. The main use for this flag is to produce JSON texts that can be transmitted over a 7-bit channel, as the encoded JSON texts will not contain any 8 bit characters. JSON->new->ascii(1)->encode([chr 0x10401]) => ["\ud801\udc01"] latin1 $json = $json->latin1([$enable]) $enabled = $json->get_latin1 If $enable is true (or missing), then the "encode" method will encode the resulting JSON text as latin1 (or iso-8859-1), escaping any characters outside the code range 0..255. The resulting string can be treated as a latin1-encoded JSON text or a native Unicode string. The "decode" method will not be affected in any way by this flag, as "decode" by default expects Unicode, which is a strict superset of latin1. If $enable is false, then the "encode" method will not escape Unicode characters unless required by the JSON syntax or other flags. See also the section *ENCODING/CODESET FLAG NOTES* later in this document. The main use for this flag is efficiently encoding binary data as JSON text, as most octets will not be escaped, resulting in a smaller encoded size. The disadvantage is that the resulting JSON text is encoded in latin1 (and must correctly be treated as such when storing and transferring), a rare encoding for JSON. It is therefore most useful when you want to store data structures known to contain binary data efficiently in files or databases, not when talking to other JSON encoders/decoders. JSON->new->latin1->encode (["\x{89}\x{abc}"] => ["\x{89}\\u0abc"] # (perl syntax, U+abc escaped, U+89 not) utf8 $json = $json->utf8([$enable]) $enabled = $json->get_utf8 If $enable is true (or missing), then the "encode" method will encode the JSON result into UTF-8, as required by many protocols, while the "decode" method expects to be handled an UTF-8-encoded string. Please note that UTF-8-encoded strings do not contain any characters outside the range 0..255, they are thus useful for bytewise/binary I/O. In future versions, enabling this option might enable autodetection of the UTF-16 and UTF-32 encoding families, as described in RFC4627. If $enable is false, then the "encode" method will return the JSON string as a (non-encoded) Unicode string, while "decode" expects thus a Unicode string. Any decoding or encoding (e.g. to UTF-8 or UTF-16) needs to be done yourself, e.g. using the Encode module. See also the section *ENCODING/CODESET FLAG NOTES* later in this document. Example, output UTF-16BE-encoded JSON: use Encode; $jsontext = encode "UTF-16BE", JSON->new->encode ($object); Example, decode UTF-32LE-encoded JSON: use Encode; $object = JSON->new->decode (decode "UTF-32LE", $jsontext); pretty $json = $json->pretty([$enable]) This enables (or disables) all of the "indent", "space_before" and "space_after" (and in the future possibly more) flags in one call to generate the most readable (or most compact) form possible. indent $json = $json->indent([$enable]) $enabled = $json->get_indent If $enable is true (or missing), then the "encode" method will use a multiline format as output, putting every array member or object/hash key-value pair into its own line, indenting them properly. If $enable is false, no newlines or indenting will be produced, and the resulting JSON text is guaranteed not to contain any "newlines". This setting has no effect when decoding JSON texts. space_before $json = $json->space_before([$enable]) $enabled = $json->get_space_before If $enable is true (or missing), then the "encode" method will add an extra optional space before the ":" separating keys from values in JSON objects. If $enable is false, then the "encode" method will not add any extra space at those places. This setting has no effect when decoding JSON texts. You will also most likely combine this setting with "space_after". Example, space_before enabled, space_after and indent disabled: {"key" :"value"} space_after $json = $json->space_after([$enable]) $enabled = $json->get_space_after If $enable is true (or missing), then the "encode" method will add an extra optional space after the ":" separating keys from values in JSON objects and extra whitespace after the "," separating key-value pairs and array members. If $enable is false, then the "encode" method will not add any extra space at those places. This setting has no effect when decoding JSON texts. Example, space_before and indent disabled, space_after enabled: {"key": "value"} relaxed $json = $json->relaxed([$enable]) $enabled = $json->get_relaxed If $enable is true (or missing), then "decode" will accept some extensions to normal JSON syntax (see below). "encode" will not be affected in anyway. *Be aware that this option makes you accept invalid JSON texts as if they were valid!*. I suggest only to use this option to parse application-specific files written by humans (configuration files, resource files etc.) If $enable is false (the default), then "decode" will only accept valid JSON texts. Currently accepted extensions are: * list items can have an end-comma JSON *separates* array elements and key-value pairs with commas. This can be annoying if you write JSON texts manually and want to be able to quickly append elements, so this extension accepts comma at the end of such items not just between them: [ 1, 2, <- this comma not normally allowed ] { "k1": "v1", "k2": "v2", <- this comma not normally allowed } * shell-style '#'-comments Whenever JSON allows whitespace, shell-style comments are additionally allowed. They are terminated by the first carriage-return or line-feed character, after which more white-space and comments are allowed. [ 1, # this comment not allowed in JSON # neither this one... ] canonical $json = $json->canonical([$enable]) $enabled = $json->get_canonical If $enable is true (or missing), then the "encode" method will output JSON objects by sorting their keys. This is adding a comparatively high overhead. If $enable is false, then the "encode" method will output key-value pairs in the order Perl stores them (which will likely change between runs of the same script, and can change even within the same run from 5.18 onwards). This option is useful if you want the same data structure to be encoded as the same JSON text (given the same overall settings). If it is disabled, the same hash might be encoded differently even if contains the same data, as key-value pairs have no inherent ordering in Perl. This setting has no effect when decoding JSON texts. This setting has currently no effect on tied hashes. allow_nonref $json = $json->allow_nonref([$enable]) $enabled = $json->get_allow_nonref If $enable is true (or missing), then the "encode" method can convert a non-reference into its corresponding string, number or null JSON value, which is an extension to RFC4627. Likewise, "decode" will accept those JSON values instead of croaking. If $enable is false, then the "encode" method will croak if it isn't passed an arrayref or hashref, as JSON texts must either be an object or array. Likewise, "decode" will croak if given something that is not a JSON object or array. Example, encode a Perl scalar as JSON value with enabled "allow_nonref", resulting in an invalid JSON text: JSON->new->allow_nonref->encode ("Hello, World!") => "Hello, World!" allow_unknown $json = $json->allow_unknown ([$enable]) $enabled = $json->get_allow_unknown If $enable is true (or missing), then "encode" will *not* throw an exception when it encounters values it cannot represent in JSON (for example, filehandles) but instead will encode a JSON "null" value. Note that blessed objects are not included here and are handled separately by c<allow_nonref>. If $enable is false (the default), then "encode" will throw an exception when it encounters anything it cannot encode as JSON. This option does not affect "decode" in any way, and it is recommended to leave it off unless you know your communications partner. allow_blessed $json = $json->allow_blessed([$enable]) $enabled = $json->get_allow_blessed See "OBJECT SERIALISATION" for details. If $enable is true (or missing), then the "encode" method will not barf when it encounters a blessed reference that it cannot convert otherwise. Instead, a JSON "null" value is encoded instead of the object. If $enable is false (the default), then "encode" will throw an exception when it encounters a blessed object that it cannot convert otherwise. This setting has no effect on "decode". convert_blessed $json = $json->convert_blessed([$enable]) $enabled = $json->get_convert_blessed See "OBJECT SERIALISATION" for details. If $enable is true (or missing), then "encode", upon encountering a blessed object, will check for the availability of the "TO_JSON" method on the object's class. If found, it will be called in scalar context and the resulting scalar will be encoded instead of the object. The "TO_JSON" method may safely call die if it wants. If "TO_JSON" returns other blessed objects, those will be handled in the same way. "TO_JSON" must take care of not causing an endless recursion cycle (== crash) in this case. The name of "TO_JSON" was chosen because other methods called by the Perl core (== not by the user of the object) are usually in upper case letters and to avoid collisions with any "to_json" function or method. If $enable is false (the default), then "encode" will not consider this type of conversion. This setting has no effect on "decode". filter_json_object $json = $json->filter_json_object([$coderef]) When $coderef is specified, it will be called from "decode" each time it decodes a JSON object. The only argument is a reference to the newly-created hash. If the code references returns a single scalar (which need not be a reference), this value (i.e. a copy of that scalar to avoid aliasing) is inserted into the deserialised data structure. If it returns an empty list (NOTE: *not* "undef", which is a valid scalar), the original deserialised hash will be inserted. This setting can slow down decoding considerably. When $coderef is omitted or undefined, any existing callback will be removed and "decode" will not change the deserialised hash in any way. Example, convert all JSON objects into the integer 5: my $js = JSON->new->filter_json_object (sub { 5 }); # returns [5] $js->decode ('[{}]'); # the given subroutine takes a hash reference. # throw an exception because allow_nonref is not enabled # so a lone 5 is not allowed. $js->decode ('{"a":1, "b":2}'); filter_json_single_key_object $json = $json->filter_json_single_key_object($key [=> $coderef]) Works remotely similar to "filter_json_object", but is only called for JSON objects having a single key named $key. This $coderef is called before the one specified via "filter_json_object", if any. It gets passed the single value in the JSON object. If it returns a single value, it will be inserted into the data structure. If it returns nothing (not even "undef" but the empty list), the callback from "filter_json_object" will be called next, as if no single-key callback were specified. If $coderef is omitted or undefined, the corresponding callback will be disabled. There can only ever be one callback for a given key. As this callback gets called less often then the "filter_json_object" one, decoding speed will not usually suffer as much. Therefore, single-key objects make excellent targets to serialise Perl objects into, especially as single-key JSON objects are as close to the type-tagged value concept as JSON gets (it's basically an ID/VALUE tuple). Of course, JSON does not support this in any way, so you need to make sure your data never looks like a serialised Perl hash. Typical names for the single object key are "__class_whatever__", or "$__dollars_are_rarely_used__$" or "}ugly_brace_placement", or even things like "__class_md5sum(classname)__", to reduce the risk of clashing with real hashes. Example, decode JSON objects of the form "{ "__widget__" => <id> }" into the corresponding $WIDGET{<id>} object: # return whatever is in $WIDGET{5}: JSON ->new ->filter_json_single_key_object (__widget__ => sub { $WIDGET{ $_[0] } }) ->decode ('{"__widget__": 5') # this can be used with a TO_JSON method in some "widget" class # for serialisation to json: sub WidgetBase::TO_JSON { my ($self) = @_; unless ($self->{id}) { $self->{id} = ..get..some..id..; $WIDGET{$self->{id}} = $self; } { __widget__ => $self->{id} } } max_depth $json = $json->max_depth([$maximum_nesting_depth]) $max_depth = $json->get_max_depth Sets the maximum nesting level (default 512) accepted while encoding or decoding. If a higher nesting level is detected in JSON text or a Perl data structure, then the encoder and decoder will stop and croak at that point. Nesting level is defined by number of hash- or arrayrefs that the encoder needs to traverse to reach a given point or the number of "{" or "[" characters without their matching closing parenthesis crossed to reach a given character in a string. Setting the maximum depth to one disallows any nesting, so that ensures that the object is only a single hash/object or array. If no argument is given, the highest possible setting will be used, which is rarely useful. max_size $json = $json->max_size([$maximum_string_size]) $max_size = $json->get_max_size Set the maximum length a JSON text may have (in bytes) where decoding is being attempted. The default is 0, meaning no limit. When "decode" is called on a string that is longer then this many bytes, it will not attempt to decode the string but throw an exception. This setting has no effect on "encode" (yet). If no argument is given, the limit check will be deactivated (same as when 0 is specified). encode $json_text = $json->encode($perl_scalar) Converts the given Perl value or data structure to its JSON representation. Croaks on error. decode $perl_scalar = $json->decode($json_text) The opposite of "encode": expects a JSON text and tries to parse it, returning the resulting simple scalar or reference. Croaks on error. decode_prefix ($perl_scalar, $characters) = $json->decode_prefix($json_text) This works like the "decode" method, but instead of raising an exception when there is trailing garbage after the first JSON object, it will silently stop parsing there and return the number of characters consumed so far. This is useful if your JSON texts are not delimited by an outer protocol and you need to know where the JSON text ends. JSON->new->decode_prefix ("[1] the tail") => ([1], 3) ADDITIONAL METHODS The following methods are for this module only. backend $backend = $json->backend Since 2.92, "backend" method returns an abstract backend module used currently, which should be JSON::Backend::XS (which inherits JSON::XS or Cpanel::JSON::XS), or JSON::Backend::PP (which inherits JSON::PP), not to monkey-patch the actual backend module globally. If you need to know what is used actually, use "isa", instead of string comparison. is_xs $boolean = $json->is_xs Returns true if the backend inherits JSON::XS or Cpanel::JSON::XS. is_pp $boolean = $json->is_pp Returns true if the backend inherits JSON::PP. property $settings = $json->property() Returns a reference to a hash that holds all the common flag settings. $json = $json->property('utf8' => 1) $value = $json->property('utf8') # 1 You can use this to get/set a value of a particular flag. INCREMENTAL PARSING This section is also taken from JSON::XS. In some cases, there is the need for incremental parsing of JSON texts. While this module always has to keep both JSON text and resulting Perl data structure in memory at one time, it does allow you to parse a JSON stream incrementally. It does so by accumulating text until it has a full JSON object, which it then can decode. This process is similar to using "decode_prefix" to see if a full JSON object is available, but is much more efficient (and can be implemented with a minimum of method calls). This module will only attempt to parse the JSON text once it is sure it has enough text to get a decisive result, using a very simple but truly incremental parser. This means that it sometimes won't stop as early as the full parser, for example, it doesn't detect mismatched parentheses. The only thing it guarantees is that it starts decoding as soon as a syntactically valid JSON text has been seen. This means you need to set resource limits (e.g. "max_size") to ensure the parser will stop parsing in the presence if syntax errors. The following methods implement this incremental parser. incr_parse $json->incr_parse( [$string] ) # void context $obj_or_undef = $json->incr_parse( [$string] ) # scalar context @obj_or_empty = $json->incr_parse( [$string] ) # list context This is the central parsing function. It can both append new text and extract objects from the stream accumulated so far (both of these functions are optional). If $string is given, then this string is appended to the already existing JSON fragment stored in the $json object. After that, if the function is called in void context, it will simply return without doing anything further. This can be used to add more text in as many chunks as you want. If the method is called in scalar context, then it will try to extract exactly *one* JSON object. If that is successful, it will return this object, otherwise it will return "undef". If there is a parse error, this method will croak just as "decode" would do (one can then use "incr_skip" to skip the erroneous part). This is the most common way of using the method. And finally, in list context, it will try to extract as many objects from the stream as it can find and return them, or the empty list otherwise. For this to work, there must be no separators (other than whitespace) between the JSON objects or arrays, instead they must be concatenated back-to-back. If an error occurs, an exception will be raised as in the scalar context case. Note that in this case, any previously-parsed JSON texts will be lost. Example: Parse some JSON arrays/objects in a given string and return them. my @objs = JSON->new->incr_parse ("[5][7][1,2]"); incr_text $lvalue_string = $json->incr_text This method returns the currently stored JSON fragment as an lvalue, that is, you can manipulate it. This *only* works when a preceding call to "incr_parse" in *scalar context* successfully returned an object. Under all other circumstances you must not call this function (I mean it. although in simple tests it might actually work, it *will* fail under real world conditions). As a special exception, you can also call this method before having parsed anything. That means you can only use this function to look at or manipulate text before or after complete JSON objects, not while the parser is in the middle of parsing a JSON object. This function is useful in two cases: a) finding the trailing text after a JSON object or b) parsing multiple JSON objects separated by non-JSON text (such as commas). incr_skip $json->incr_skip This will reset the state of the incremental parser and will remove the parsed text from the input buffer so far. This is useful after "incr_parse" died, in which case the input buffer and incremental parser state is left unchanged, to skip the text parsed so far and to reset the parse state. The difference to "incr_reset" is that only text until the parse error occurred is removed. incr_reset $json->incr_reset This completely resets the incremental parser, that is, after this call, it will be as if the parser had never parsed anything. This is useful if you want to repeatedly parse JSON objects and want to ignore any trailing data, which means you have to reset the parser after each successful decode. MAPPING Most of this section is also taken from JSON::XS. This section describes how the backend modules map Perl values to JSON values and vice versa. These mappings are designed to "do the right thing" in most circumstances automatically, preserving round-tripping characteristics (what you put in comes out as something equivalent). For the more enlightened: note that in the following descriptions, lowercase *perl* refers to the Perl interpreter, while uppercase *Perl* refers to the abstract Perl language itself. JSON -> PERL object A JSON object becomes a reference to a hash in Perl. No ordering of object keys is preserved (JSON does not preserver object key ordering itself). array A JSON array becomes a reference to an array in Perl. string A JSON string becomes a string scalar in Perl - Unicode codepoints in JSON are represented by the same codepoints in the Perl string, so no manual decoding is necessary. number A JSON number becomes either an integer, numeric (floating point) or string scalar in perl, depending on its range and any fractional parts. On the Perl level, there is no difference between those as Perl handles all the conversion details, but an integer may take slightly less memory and might represent more values exactly than floating point numbers. If the number consists of digits only, this module will try to represent it as an integer value. If that fails, it will try to represent it as a numeric (floating point) value if that is possible without loss of precision. Otherwise it will preserve the number as a string value (in which case you lose roundtripping ability, as the JSON number will be re-encoded to a JSON string). Numbers containing a fractional or exponential part will always be represented as numeric (floating point) values, possibly at a loss of precision (in which case you might lose perfect roundtripping ability, but the JSON number will still be re-encoded as a JSON number). Note that precision is not accuracy - binary floating point values cannot represent most decimal fractions exactly, and when converting from and to floating point, this module only guarantees precision up to but not including the least significant bit. true, false These JSON atoms become "JSON::true" and "JSON::false", respectively. They are overloaded to act almost exactly like the numbers 1 and 0. You can check whether a scalar is a JSON boolean by using the "JSON::is_bool" function. null A JSON null atom becomes "undef" in Perl. shell-style comments ("# *text*") As a nonstandard extension to the JSON syntax that is enabled by the "relaxed" setting, shell-style comments are allowed. They can start anywhere outside strings and go till the end of the line. PERL -> JSON The mapping from Perl to JSON is slightly more difficult, as Perl is a truly typeless language, so we can only guess which JSON type is meant by a Perl value. hash references Perl hash references become JSON objects. As there is no inherent ordering in hash keys (or JSON objects), they will usually be encoded in a pseudo-random order. This module can optionally sort the hash keys (determined by the *canonical* flag), so the same data structure will serialise to the same JSON text (given same settings and version of the same backend), but this incurs a runtime overhead and is only rarely useful, e.g. when you want to compare some JSON text against another for equality. array references Perl array references become JSON arrays. other references Other unblessed references are generally not allowed and will cause an exception to be thrown, except for references to the integers 0 and 1, which get turned into "false" and "true" atoms in JSON. You can also use "JSON::false" and "JSON::true" to improve readability. encode_json [\0,JSON::true] # yields [false,true] JSON::true, JSON::false, JSON::null These special values become JSON true and JSON false values, respectively. You can also use "\1" and "\0" directly if you want. blessed objects Blessed objects are not directly representable in JSON, but "JSON::XS" allows various ways of handling objects. See "OBJECT SERIALISATION", below, for details. simple scalars Simple Perl scalars (any scalar that is not a reference) are the most difficult objects to encode: this module will encode undefined scalars as JSON "null" values, scalars that have last been used in a string context before encoding as JSON strings, and anything else as number value: # dump as number encode_json [2] # yields [2] encode_json [-3.0e17] # yields [-3e+17] my $value = 5; encode_json [$value] # yields [5] # used as string, so dump as string print $value; encode_json [$value] # yields ["5"] # undef becomes null encode_json [undef] # yields [null] You can force the type to be a string by stringifying it: my $x = 3.1; # some variable containing a number "$x"; # stringified $x .= ""; # another, more awkward way to stringify print $x; # perl does it for you, too, quite often You can force the type to be a number by numifying it: my $x = "3"; # some variable containing a string $x += 0; # numify it, ensuring it will be dumped as a number $x *= 1; # same thing, the choice is yours. You can not currently force the type in other, less obscure, ways. Tell me if you need this capability (but don't forget to explain why it's needed :). Note that numerical precision has the same meaning as under Perl (so binary to decimal conversion follows the same rules as in Perl, which can differ to other languages). Also, your perl interpreter might expose extensions to the floating point numbers of your platform, such as infinities or NaN's - these cannot be represented in JSON, and it is an error to pass those in. OBJECT SERIALISATION As for Perl objects, this module only supports a pure JSON representation (without the ability to deserialise the object automatically again). SERIALISATION What happens when this module encounters a Perl object depends on the "allow_blessed" and "convert_blessed" settings, which are used in this order: 1. "convert_blessed" is enabled and the object has a "TO_JSON" method. In this case, the "TO_JSON" method of the object is invoked in scalar context. It must return a single scalar that can be directly encoded into JSON. This scalar replaces the object in the JSON text. For example, the following "TO_JSON" method will convert all URI objects to JSON strings when serialised. The fact that these values originally were URI objects is lost. sub URI::TO_JSON { my ($uri) = @_; $uri->as_string } 2. "allow_blessed" is enabled. The object will be serialised as a JSON null value. 3. none of the above If none of the settings are enabled or the respective methods are missing, this module throws an exception. ENCODING/CODESET FLAG NOTES This section is taken from JSON::XS. The interested reader might have seen a number of flags that signify encodings or codesets - "utf8", "latin1" and "ascii". There seems to be some confusion on what these do, so here is a short comparison: "utf8" controls whether the JSON text created by "encode" (and expected by "decode") is UTF-8 encoded or not, while "latin1" and "ascii" only control whether "encode" escapes character values outside their respective codeset range. Neither of these flags conflict with each other, although some combinations make less sense than others. Care has been taken to make all flags symmetrical with respect to "encode" and "decode", that is, texts encoded with any combination of these flag values will be correctly decoded when the same flags are used - in general, if you use different flag settings while encoding vs. when decoding you likely have a bug somewhere. Below comes a verbose discussion of these flags. Note that a "codeset" is simply an abstract set of character-codepoint pairs, while an encoding takes those codepoint numbers and *encodes* them, in our case into octets. Unicode is (among other things) a codeset, UTF-8 is an encoding, and ISO-8859-1 (= latin 1) and ASCII are both codesets *and* encodings at the same time, which can be confusing. "utf8" flag disabled When "utf8" is disabled (the default), then "encode"/"decode" generate and expect Unicode strings, that is, characters with high ordinal Unicode values (> 255) will be encoded as such characters, and likewise such characters are decoded as-is, no changes to them will be done, except "(re-)interpreting" them as Unicode codepoints or Unicode characters, respectively (to Perl, these are the same thing in strings unless you do funny/weird/dumb stuff). This is useful when you want to do the encoding yourself (e.g. when you want to have UTF-16 encoded JSON texts) or when some other layer does the encoding for you (for example, when printing to a terminal using a filehandle that transparently encodes to UTF-8 you certainly do NOT want to UTF-8 encode your data first and have Perl encode it another time). "utf8" flag enabled If the "utf8"-flag is enabled, "encode"/"decode" will encode all characters using the corresponding UTF-8 multi-byte sequence, and will expect your input strings to be encoded as UTF-8, that is, no "character" of the input string must have any value > 255, as UTF-8 does not allow that. The "utf8" flag therefore switches between two modes: disabled means you will get a Unicode string in Perl, enabled means you get an UTF-8 encoded octet/binary string in Perl. "latin1" or "ascii" flags enabled With "latin1" (or "ascii") enabled, "encode" will escape characters with ordinal values > 255 (> 127 with "ascii") and encode the remaining characters as specified by the "utf8" flag. If "utf8" is disabled, then the result is also correctly encoded in those character sets (as both are proper subsets of Unicode, meaning that a Unicode string with all character values < 256 is the same thing as a ISO-8859-1 string, and a Unicode string with all character values < 128 is the same thing as an ASCII string in Perl). If "utf8" is enabled, you still get a correct UTF-8-encoded string, regardless of these flags, just some more characters will be escaped using "\uXXXX" then before. Note that ISO-8859-1-*encoded* strings are not compatible with UTF-8 encoding, while ASCII-encoded strings are. That is because the ISO-8859-1 encoding is NOT a subset of UTF-8 (despite the ISO-8859-1 *codeset* being a subset of Unicode), while ASCII is. Surprisingly, "decode" will ignore these flags and so treat all input values as governed by the "utf8" flag. If it is disabled, this allows you to decode ISO-8859-1- and ASCII-encoded strings, as both strict subsets of Unicode. If it is enabled, you can correctly decode UTF-8 encoded strings. So neither "latin1" nor "ascii" are incompatible with the "utf8" flag - they only govern when the JSON output engine escapes a character or not. The main use for "latin1" is to relatively efficiently store binary data as JSON, at the expense of breaking compatibility with most JSON decoders. The main use for "ascii" is to force the output to not contain characters with values > 127, which means you can interpret the resulting string as UTF-8, ISO-8859-1, ASCII, KOI8-R or most about any character set and 8-bit-encoding, and still get the same data structure back. This is useful when your channel for JSON transfer is not 8-bit clean or the encoding might be mangled in between (e.g. in mail), and works because ASCII is a proper subset of most 8-bit and multibyte encodings in use in the world. BACKWARD INCOMPATIBILITY Since version 2.90, stringification (and string comparison) for "JSON::true" and "JSON::false" has not been overloaded. It shouldn't matter as long as you treat them as boolean values, but a code that expects they are stringified as "true" or "false" doesn't work as you have expected any more. if (JSON::true eq 'true') { # now fails print "The result is $JSON::true now."; # => The result is 1 now. And now these boolean values don't inherit JSON::Boolean, either. When you need to test a value is a JSON boolean value or not, use "JSON::is_bool" function, instead of testing the value inherits a particular boolean class or not. BUGS Please report bugs on backend selection and additional features this module provides to RT or GitHub issues for this module: https://rt.cpan.org/Public/Dist/Display.html?Queue=JSON https://github.com/makamaka/JSON/issues Please report bugs and feature requests on decoding/encoding and boolean behaviors to the author of the backend module you are using. SEE ALSO JSON::XS, Cpanel::JSON::XS, JSON::PP for backends. JSON::MaybeXS, an alternative that prefers Cpanel::JSON::XS. "RFC4627"(<http://www.ietf.org/rfc/rfc4627.txt>) AUTHOR Makamaka Hannyaharamitu, <makamaka[at]cpan.org> JSON::XS was written by Marc Lehmann <schmorp[at]schmorp.de> The release of this new version owes to the courtesy of Marc Lehmann. COPYRIGHT AND LICENSE Copyright 2005-2013 by Makamaka Hannyaharamitu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. home/.cpan/build/Sub-Uplevel-0.2800-0/README 0000644 00000012537 15125143274 0013513 0 ustar 00 NAME Sub::Uplevel - apparently run a function in a higher stack frame VERSION version 0.2800 SYNOPSIS use Sub::Uplevel; sub foo { print join " - ", caller; } sub bar { uplevel 1, \&foo; } #line 11 bar(); # main - foo.plx - 11 DESCRIPTION Like Tcl's uplevel() function, but not quite so dangerous. The idea is just to fool caller(). All the really naughty bits of Tcl's uplevel() are avoided. THIS IS NOT THE SORT OF THING YOU WANT TO DO EVERYDAY uplevel uplevel $num_frames, \&func, @args; Makes the given function think it's being executed $num_frames higher than the current stack level. So when they use caller($frames) it will actually give caller($frames + $num_frames) for them. "uplevel(1, \&some_func, @_)" is effectively "goto &some_func" but you don't immediately exit the current subroutine. So while you can't do this: sub wrapper { print "Before\n"; goto &some_func; print "After\n"; } you can do this: sub wrapper { print "Before\n"; my @out = uplevel 1, &some_func; print "After\n"; return @out; } "uplevel" has the ability to issue a warning if $num_frames is more than the current call stack depth, although this warning is disabled and compiled out by default as the check is relatively expensive. To enable the check for debugging or testing, you should set the global $Sub::Uplevel::CHECK_FRAMES to true before loading Sub::Uplevel for the first time as follows: #!/usr/bin/perl BEGIN { $Sub::Uplevel::CHECK_FRAMES = 1; } use Sub::Uplevel; Setting or changing the global after the module has been loaded will have no effect. EXAMPLE The main reason I wrote this module is so I could write wrappers around functions and they wouldn't be aware they've been wrapped. use Sub::Uplevel; my $original_foo = \&foo; *foo = sub { my @output = uplevel 1, $original_foo; print "foo() returned: @output"; return @output; }; If this code frightens you you should not use this module. BUGS and CAVEATS Well, the bad news is uplevel() is about 5 times slower than a normal function call. XS implementation anyone? It also slows down every invocation of caller(), regardless of whether uplevel() is in effect. Sub::Uplevel overrides CORE::GLOBAL::caller temporarily for the scope of each uplevel call. It does its best to work with any previously existing CORE::GLOBAL::caller (both when Sub::Uplevel is first loaded and within each uplevel call) such as from Contextual::Return or Hook::LexWrap. However, if you are routinely using multiple modules that override CORE::GLOBAL::caller, you are probably asking for trouble. You should load Sub::Uplevel as early as possible within your program. As with all CORE::GLOBAL overloading, the overload will not affect modules that have already been compiled prior to the overload. One module that often is unavoidably loaded prior to Sub::Uplevel is Exporter. To forcibly recompile Exporter (and Exporter::Heavy) after loading Sub::Uplevel, use it with the ":aggressive" tag: use Sub::Uplevel qw/:aggressive/; The private function "Sub::Uplevel::_force_reload()" may be passed a list of additional modules to reload if ":aggressive" is not aggressive enough. Reloading modules may break things, so only use this as a last resort. As of version 0.20, Sub::Uplevel requires Perl 5.6 or greater. HISTORY Those who do not learn from HISTORY are doomed to repeat it. The lesson here is simple: Don't sit next to a Tcl programmer at the dinner table. THANKS Thanks to Brent Welch, Damian Conway and Robin Houston. See http://www.perl.com/perl/misc/Artistic.html SEE ALSO PadWalker (for the similar idea with lexicals), Hook::LexWrap, Tcl's uplevel() at http://www.scriptics.com/man/tcl8.4/TclCmd/uplevel.htm SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at <https://github.com/Perl-Toolchain-Gang/Sub-Uplevel/issues>. You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/Perl-Toolchain-Gang/Sub-Uplevel> git clone https://github.com/Perl-Toolchain-Gang/Sub-Uplevel.git AUTHORS * Michael Schwern <mschwern@cpan.org> * David Golden <dagolden@cpan.org> CONTRIBUTORS * Adam Kennedy <adamk@cpan.org> * Alexandr Ciornii <alexchorny@gmail.com> * David Golden <xdg@xdg.me> * Graham Ollis <plicease@cpan.org> * J. Nick Koston <nick@cpanel.net> * Michael Gray <mg13@sanger.ac.uk> COPYRIGHT AND LICENSE This software is copyright (c) 2017 by Michael Schwern and David Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. home/.cpan/build/File-Copy-Recursive-0.45-0/README 0000644 00000001733 15125143314 0014732 0 ustar 00 File/Copy/Recursive version 0.43 ================================ This module has 3 functions, one to copy files only, one to copy directories only and one to do either depending on the argument's type. The depth to which a directory structure is copied can be set with: $File::Copy::Recursive::Maxdepth setting it back to false or non numeric value will turn it back to unlimited. All functions attempt to preserve each copied file's mode unless you set $File::Copy::Recursive::KeepMode to false. See perldoc File::Copy::Recursive for more info INSTALLATION To install this module type the following: perl Makefile.PL make make test make install or perl -MCPAN -e 'install File::Copy::Recursive;' DEPENDENCIES This module requires these other modules and libraries: File::Copy File::Spec COPYRIGHT AND LICENCE Copyright (C) 2004 Daniel Muey This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. home/.cpan/build/HTTP-CookieJar-0.014-0/README 0000644 00000014652 15125143316 0013703 0 ustar 00 NAME HTTP::CookieJar - A minimalist HTTP user agent cookie jar VERSION version 0.014 SYNOPSIS use HTTP::CookieJar; my $jar = HTTP::CookieJar->new; # add cookie received from a request $jar->add( "http://www.example.com/", "CUSTOMER=WILE_E_COYOTE; Path=/; Domain=example.com" ); # extract cookie header for a given request my $cookie = $jar->cookie_header( "http://www.example.com/" ); DESCRIPTION This module implements a minimalist HTTP user agent cookie jar in conformance with RFC 6265 <http://tools.ietf.org/html/rfc6265>. Unlike the commonly used HTTP::Cookies module, this module does not require use of HTTP::Request and HTTP::Response objects. An LWP-compatible adapter is available as HTTP::CookieJar::LWP. CONSTRUCTORS new my $jar = HTTP::CookieJar->new; Return a new, empty cookie jar METHODS add $jar->add( "http://www.example.com/", "lang=en-US; Path=/; Domain=example.com" ); Given a request URL and a "Set-Cookie" header string, attempts to adds the cookie to the jar. If the cookie is expired, instead it deletes any matching cookie from the jar. A "Max-Age" attribute will be converted to an absolute "Expires" attribute. It will throw an exception if the request URL is missing or invalid. Returns true if successful cookie processing or undef/empty-list on failure. clear $jar->clear Empties the cookie jar. cookies_for my @cookies = $jar->cookies_for("http://www.example.com/foo/bar"); Given a request URL, returns a list of hash references representing cookies that should be sent. The hash references are copies -- changing values will not change the cookies in the jar. Cookies set "secure" will only be returned if the request scheme is "https". Expired cookies will not be returned. Keys of a cookie hash reference might include: * name -- the name of the cookie * value -- the value of the cookie * domain -- the domain name to which the cookie applies * path -- the path to which the cookie applies * expires -- if present, when the cookie expires in epoch seconds * secure -- if present, the cookie was set "Secure" * httponly -- if present, the cookie was set "HttpOnly" * hostonly -- if present, the cookie may only be used with the domain as a host * creation_time -- epoch time when the cookie was first stored * last_access_time -- epoch time when the cookie was last accessed (i.e. "now") Keep in mind that "httponly" means it should only be used in requests and not made available via Javascript, etc. This is pretty meaningless for Perl user agents. Generally, user agents should use the "cookie_header" method instead. It will throw an exception if the request URL is missing or invalid. cookie_header my $header = $jar->cookie_header("http://www.example.com/foo/bar"); Given a request URL, returns a correctly-formatted string with all relevant cookies for the request. This string is ready to be used in a "Cookie" header in an HTTP request. E.g.: SID=31d4d96e407aad42; lang=en-US It follows the same exclusion rules as "cookies_for". If the request is invalid or no cookies apply, it will return an empty string. dump_cookies my @list = $jar->dump_cookies; my @list = $jar->dump_cookies( { persistent => 1 } ); Returns a list of raw cookies in string form. The strings resemble what would be received from "Set-Cookie" headers, but with additional internal fields. The list is only intended for use with "load_cookies" to allow cookie jar persistence. If a hash reference with a true "persistent" key is given as an argument, cookies without an "Expires" time (i.e. "session cookies") will be omitted. Here is a trivial example of saving a cookie jar file with Path::Tiny: path("jar.txt")->spew( join "\n", $jar->dump_cookies ); load_cookies $jar->load_cookies( @cookies ); Given a list of cookie strings from "dump_cookies", it adds them to the cookie jar. Cookies added in this way will supersede any existing cookies with similar domain, path and name. It returns the jar object for convenience when loading a new object: my $jar = HTTP::CookieJar->new->load_cookies( @cookies ); Here is a trivial example of loading a cookie jar file with Path::Tiny: my $jar = HTTP::CookieJar->new->load_cookies( path("jar.txt")->lines ); LIMITATIONS AND CAVEATS RFC 6265 vs prior standards This modules adheres as closely as possible to the user-agent rules of RFC 6265. Therefore, it does not handle nor generate "Set-Cookie2" and "Cookie2" headers, implement ".local" suffixes, or do path/domain matching in accord with prior RFC's. Internationalized domain names Internationalized domain names given in requests must be properly encoded in ASCII form. Public suffixes If Mozilla::PublicSuffix is installed, cookie domains will be checked against the public suffix list. Public suffix cookies are only allowed as host-only cookies. Third-party cookies According to RFC 6265, a cookie may be accepted only if has no "Domain" attribute (in which case it is "host-only") or if the "Domain" attribute is a suffix of the request URL. This effectively prohibits Site A from setting a cookie for unrelated Site B, which is one potential third-party cookie vector. SEE ALSO * HTTP::Cookies * Mojo::UserAgent::CookieJar SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/HTTP-CookieJar/issues>. You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/dagolden/HTTP-CookieJar> git clone https://github.com/dagolden/HTTP-CookieJar.git AUTHOR David Golden <dagolden@cpan.org> CONTRIBUTORS * Dan Book <grinnz@grinnz.com> * David Golden <xdg@xdg.me> * jvolkening <jdv@base2bio.com> COPYRIGHT AND LICENSE This software is Copyright (c) 2013 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 home/.cpan/build/Test-Fatal-0.017-0/README 0000644 00000000610 15125143325 0013214 0 ustar 00 This archive contains the distribution Test-Fatal, version 0.017: incredibly simple helpers for testing code with exceptions This software is copyright (c) 2010 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.029. home/.cpan/build/Test-LeakTrace-0.17-0/README 0000644 00000001007 15125143330 0013735 0 ustar 00 This is Perl module Test::LeakTrace. INSTALLATION Test::LeakTrace installation is straightforward. If your CPAN shell is set up, you should just be able to do $ cpan Test::LeakTrace Download it, unpack it, then build it as per the usual: $ perl Makefile.PL $ make && make test Then install it: $ make install DOCUMENTATION Test::LeakTrace documentation is available as in POD. So you can do: $ perldoc Test::LeakTrace to read the documentation online with your favorite pager. Goro Fuji home/.cpan/build/Test-Needs-0.002010-0/README 0000644 00000005635 15125143331 0013447 0 ustar 00 NAME Test::Needs - Skip tests when modules not available SYNOPSIS # need one module use Test::Needs 'Some::Module'; # need multiple modules use Test::Needs 'Some::Module', 'Some::Other::Module'; # need a given version of a module use Test::Needs { 'Some::Module' => '1.005', }; # check later use Test::Needs; test_needs 'Some::Module'; # skips remainder of subtest use Test::More; use Test::Needs; subtest 'my subtest' => sub { test_needs 'Some::Module'; ... }; # check perl version use Test::Needs { perl => 5.020 }; DESCRIPTION Skip test scripts if modules are not available. The requested modules will be loaded, and optionally have their versions checked. If the module is missing, the test script will be skipped. Modules that are found but fail to compile will exit with an error rather than skip. If used in a subtest, the remainder of the subtest will be skipped. Skipping will work even if some tests have already been run, or if a plan has been declared. Versions are checked via a "$module->VERSION($wanted_version)" call. Versions must be provided in a format that will be accepted. No extra processing is done on them. If "perl" is used as a module, the version is checked against the running perl version ($]). The version can be specified as a number, dotted-decimal string, v-string, or version object. If the "RELEASE_TESTING" environment variable is set, the tests will fail rather than skip. Subtests will be aborted, but the test script will continue running after that point. EXPORTS test_needs Has the same interface as when using Test::Needs in a "use". SEE ALSO Test::Requires A similar module, with some important differences. Test::Requires will act as a "use" statement (despite its name), calling the import sub. Under "RELEASE_TESTING", it will BAIL_OUT if a module fails to load rather than using a normal test fail. It also doesn't distinguish between missing modules and broken modules. Test2::Require::Module Part of the Test2 ecosystem. Only supports running as a "use" command to skip an entire plan. Test2::Require::Perl Part of the Test2 ecosystem. Only supports running as a "use" command to skip an entire plan. Checks perl versions. Test::If Acts as a "use" statement. Only supports running as a "use" command to skip an entire plan. Can skip based on subref results. AUTHORS haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org> CONTRIBUTORS None so far. COPYRIGHT AND LICENSE Copyright (c) 2016 the Test::Needs "AUTHORS" and "CONTRIBUTORS" as listed above. This library is free software and may be distributed under the same terms as perl itself. See <http://dev.perl.org/licenses/>. home/.cpan/build/Devel-CheckLib-1.16-0/README 0000644 00000000401 15125143352 0013667 0 ustar 00 This module provides a way of checking whether a particular library and its headers are available, by attempting to compile a simple program and link against it. To install, do the usual dance: perl Makefile.PL make make test make install home/.cpan/build/Exporter-5.78-0/README 0000644 00000041346 15125143363 0013031 0 ustar 00 NAME Exporter - Implements default import method for modules SYNOPSIS In module YourModule.pm: package YourModule; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(munge frobnicate); # symbols to export on request or package YourModule; use Exporter 'import'; # gives you Exporter's import() method directly @EXPORT_OK = qw(munge frobnicate); # symbols to export on request In other files which wish to use "YourModule": use YourModule qw(frobnicate); # import listed symbols frobnicate ($left, $right) # calls YourModule::frobnicate Take a look at "Good Practices" for some variants you will like to use in modern Perl code. DESCRIPTION The Exporter module implements an "import" method which allows a module to export functions and variables to its users' namespaces. Many modules use Exporter rather than implementing their own "import" method because Exporter provides a highly flexible interface, with an implementation optimised for the common case. Perl automatically calls the "import" method when processing a "use" statement for a module. Modules and "use" are documented in perlfunc and perlmod. Understanding the concept of modules and how the "use" statement operates is important to understanding the Exporter. How to Export The arrays @EXPORT and @EXPORT_OK in a module hold lists of symbols that are going to be exported into the users name space by default, or which they can request to be exported, respectively. The symbols can represent functions, scalars, arrays, hashes, or typeglobs. The symbols must be given by full name with the exception that the ampersand in front of a function is optional, e.g. @EXPORT = qw(afunc $scalar @array); # afunc is a function @EXPORT_OK = qw(&bfunc %hash *typeglob); # explicit prefix on &bfunc If you are only exporting function names it is recommended to omit the ampersand, as the implementation is faster this way. Selecting What To Export Do not export method names! Do not export anything else by default without a good reason! Exports pollute the namespace of the module user. If you must export try to use @EXPORT_OK in preference to @EXPORT and avoid short or common symbol names to reduce the risk of name clashes. Generally anything not exported is still accessible from outside the module using the "YourModule::item_name" (or "$blessed_ref->method") syntax. By convention you can use a leading underscore on names to informally indicate that they are 'internal' and not for public use. (It is actually possible to get private functions by saying: my $subref = sub { ... }; $subref->(@args); # Call it as a function $obj->$subref(@args); # Use it as a method However if you use them for methods it is up to you to figure out how to make inheritance work.) As a general rule, if the module is trying to be object oriented then export nothing. If it's just a collection of functions then @EXPORT_OK anything but use @EXPORT with caution. For function and method names use barewords in preference to names prefixed with ampersands for the export lists. Other module design guidelines can be found in perlmod. How to Import In other files which wish to use your module there are three basic ways for them to load your module and import its symbols: "use YourModule;" This imports all the symbols from YourModule's @EXPORT into the namespace of the "use" statement. "use YourModule ();" This causes perl to load your module but does not import any symbols. "use YourModule qw(...);" This imports only the symbols listed by the caller into their namespace. All listed symbols must be in your @EXPORT or @EXPORT_OK, else an error occurs. The advanced export features of Exporter are accessed like this, but with list entries that are syntactically distinct from symbol names. Unless you want to use its advanced features, this is probably all you need to know to use Exporter. Advanced features Specialised Import Lists If any of the entries in an import list begins with !, : or / then the list is treated as a series of specifications which either add to or delete from the list of names to import. They are processed left to right. Specifications are in the form: [!]name This name only [!]:DEFAULT All names in @EXPORT [!]:tag All names in $EXPORT_TAGS{tag} anonymous list [!]/pattern/ All names in @EXPORT and @EXPORT_OK which match A leading ! indicates that matching names should be deleted from the list of names to import. If the first specification is a deletion it is treated as though preceded by :DEFAULT. If you just want to import extra names in addition to the default set you will still need to include :DEFAULT explicitly. e.g., Module.pm defines: @EXPORT = qw(A1 A2 A3 A4 A5); @EXPORT_OK = qw(B1 B2 B3 B4 B5); %EXPORT_TAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]); Note that you cannot use tags in @EXPORT or @EXPORT_OK. Names in EXPORT_TAGS must also appear in @EXPORT or @EXPORT_OK. An application using Module can say something like: use Module qw(:DEFAULT :T2 !B3 A3); Other examples include: use Socket qw(!/^[AP]F_/ !SOMAXCONN !SOL_SOCKET); use POSIX qw(:errno_h :termios_h !TCSADRAIN !/^EXIT/); Remember that most patterns (using //) will need to be anchored with a leading ^, e.g., "/^EXIT/" rather than "/EXIT/". You can say "BEGIN { $Exporter::Verbose=1 }" to see how the specifications are being processed and what is actually being imported into modules. Exporting without using Exporter's import method Exporter has a special method, 'export_to_level' which is used in situations where you can't directly call Exporter's import method. The export_to_level method looks like: MyPackage->export_to_level($where_to_export, $package, @what_to_export); where $where_to_export is an integer telling how far up the calling stack to export your symbols, and @what_to_export is an array telling what symbols *to* export (usually this is @_). The $package argument is currently unused. For example, suppose that you have a module, A, which already has an import function: package A; @ISA = qw(Exporter); @EXPORT_OK = qw ($b); sub import { $A::b = 1; # not a very useful import method } and you want to Export symbol $A::b back to the module that called package A. Since Exporter relies on the import method to work, via inheritance, as it stands Exporter::import() will never get called. Instead, say the following: package A; @ISA = qw(Exporter); @EXPORT_OK = qw ($b); sub import { $A::b = 1; A->export_to_level(1, @_); } This will export the symbols one level 'above' the current package - ie: to the program or module that used package A. Note: Be careful not to modify @_ at all before you call export_to_level - or people using your package will get very unexplained results! Exporting without inheriting from Exporter By including Exporter in your @ISA you inherit an Exporter's import() method but you also inherit several other helper methods which you probably don't want. To avoid this you can do package YourModule; use Exporter qw( import ); which will export Exporter's own import() method into YourModule. Everything will work as before but you won't need to include Exporter in @YourModule::ISA. Note: This feature was introduced in version 5.57 of Exporter, released with perl 5.8.3. Module Version Checking The Exporter module will convert an attempt to import a number from a module into a call to "$module_name->require_version($value)". This can be used to validate that the version of the module being used is greater than or equal to the required version. The Exporter module supplies a default "require_version" method which checks the value of $VERSION in the exporting module. Since the default "require_version" method treats the $VERSION number as a simple numeric value it will regard version 1.10 as lower than 1.9. For this reason it is strongly recommended that you use numbers with at least two decimal places, e.g., 1.09. Managing Unknown Symbols In some situations you may want to prevent certain symbols from being exported. Typically this applies to extensions which have functions or constants that may not exist on some systems. The names of any symbols that cannot be exported should be listed in the @EXPORT_FAIL array. If a module attempts to import any of these symbols the Exporter will give the module an opportunity to handle the situation before generating an error. The Exporter will call an export_fail method with a list of the failed symbols: @failed_symbols = $module_name->export_fail(@failed_symbols); If the "export_fail" method returns an empty list then no error is recorded and all the requested symbols are exported. If the returned list is not empty then an error is generated for each symbol and the export fails. The Exporter provides a default "export_fail" method which simply returns the list unchanged. Uses for the "export_fail" method include giving better error messages for some symbols and performing lazy architectural checks (put more symbols into @EXPORT_FAIL by default and then take them out if someone actually tries to use them and an expensive check shows that they are usable on that platform). Tag Handling Utility Functions Since the symbols listed within %EXPORT_TAGS must also appear in either @EXPORT or @EXPORT_OK, two utility functions are provided which allow you to easily add tagged sets of symbols to @EXPORT or @EXPORT_OK: %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]); Exporter::export_tags('foo'); # add aa, bb and cc to @EXPORT Exporter::export_ok_tags('bar'); # add aa, cc and dd to @EXPORT_OK Any names which are not tags are added to @EXPORT or @EXPORT_OK unchanged but will trigger a warning (with "-w") to avoid misspelt tags names being silently added to @EXPORT or @EXPORT_OK. Future versions may make this a fatal error. Generating combined tags If several symbol categories exist in %EXPORT_TAGS, it's usually useful to create the utility ":all" to simplify "use" statements. The simplest way to do this is: %EXPORT_TAGS = (foo => [qw(aa bb cc)], bar => [qw(aa cc dd)]); # add all the other ":class" tags to the ":all" class, # deleting duplicates { my %seen; push @{$EXPORT_TAGS{all}}, grep {!$seen{$_}++} @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS; } CGI.pm creates an ":all" tag which contains some (but not really all) of its categories. That could be done with one small change: # add some of the other ":class" tags to the ":all" class, # deleting duplicates { my %seen; push @{$EXPORT_TAGS{all}}, grep {!$seen{$_}++} @{$EXPORT_TAGS{$_}} foreach qw/html2 html3 netscape form cgi internal/; } Note that the tag names in %EXPORT_TAGS don't have the leading ':'. "AUTOLOAD"ed Constants Many modules make use of "AUTOLOAD"ing for constant subroutines to avoid having to compile and waste memory on rarely used values (see perlsub for details on constant subroutines). Calls to such constant subroutines are not optimized away at compile time because they can't be checked at compile time for constancy. Even if a prototype is available at compile time, the body of the subroutine is not (it hasn't been "AUTOLOAD"ed yet). perl needs to examine both the "()" prototype and the body of a subroutine at compile time to detect that it can safely replace calls to that subroutine with the constant value. A workaround for this is to call the constants once in a "BEGIN" block: package My ; use Socket ; foo( SO_LINGER ); ## SO_LINGER NOT optimized away; called at runtime BEGIN { SO_LINGER } foo( SO_LINGER ); ## SO_LINGER optimized away at compile time. This forces the "AUTOLOAD" for "SO_LINGER" to take place before SO_LINGER is encountered later in "My" package. If you are writing a package that "AUTOLOAD"s, consider forcing an "AUTOLOAD" for any constants explicitly imported by other packages or which are usually used when your package is "use"d. Good Practices Declaring @EXPORT_OK and Friends When using "Exporter" with the standard "strict" and "warnings" pragmas, the "our" keyword is needed to declare the package variables @EXPORT_OK, @EXPORT, @ISA, etc. our @ISA = qw(Exporter); our @EXPORT_OK = qw(munge frobnicate); If backward compatibility for Perls under 5.6 is important, one must write instead a "use vars" statement. use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); @EXPORT_OK = qw(munge frobnicate); Playing Safe There are some caveats with the use of runtime statements like "require Exporter" and the assignment to package variables, which can very subtle for the unaware programmer. This may happen for instance with mutually recursive modules, which are affected by the time the relevant constructions are executed. The ideal (but a bit ugly) way to never have to think about that is to use "BEGIN" blocks. So the first part of the "SYNOPSIS" code could be rewritten as: package YourModule; use strict; use warnings; our (@ISA, @EXPORT_OK); BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(munge frobnicate); # symbols to export on request } The "BEGIN" will assure that the loading of Exporter.pm and the assignments to @ISA and @EXPORT_OK happen immediately, leaving no room for something to get awry or just plain wrong. With respect to loading "Exporter" and inheriting, there are alternatives with the use of modules like "base" and "parent". use base qw( Exporter ); # or use parent qw( Exporter ); Any of these statements are nice replacements for "BEGIN { require Exporter; @ISA = qw(Exporter); }" with the same compile-time effect. The basic difference is that "base" code interacts with declared "fields" while "parent" is a streamlined version of the older "base" code to just establish the IS-A relationship. For more details, see the documentation and code of base and parent. Another thorough remedy to that runtime vs. compile-time trap is to use Exporter::Easy, which is a wrapper of Exporter that allows all boilerplate code at a single gulp in the use statement. use Exporter::Easy ( OK => [ qw(munge frobnicate) ], ); # @ISA setup is automatic # all assignments happen at compile time What not to Export You have been warned already in "Selecting What To Export" to not export: * method names (because you don't need to and that's likely to not do what you want), * anything by default (because you don't want to surprise your users... badly) * anything you don't need to (because less is more) There's one more item to add to this list. Do not export variable names. Just because "Exporter" lets you do that, it does not mean you should. @EXPORT_OK = qw( $svar @avar %hvar ); # DON'T! Exporting variables is not a good idea. They can change under the hood, provoking horrible effects at-a-distance, that are too hard to track and to fix. Trust me: they are not worth it. To provide the capability to set/get class-wide settings, it is best instead to provide accessors as subroutines or class methods instead. SEE ALSO "Exporter" is definitely not the only module with symbol exporter capabilities. At CPAN, you may find a bunch of them. Some are lighter. Some provide improved APIs and features. Peek the one that fits your needs. The following is a sample list of such modules. Exporter::Easy Exporter::Lite Exporter::Renaming Exporter::Tidy Sub::Exporter / Sub::Installer Perl6::Export / Perl6::Export::Attrs LICENSE This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. home/.cpan/build/Mock-Config-0.03-0/README 0000644 00000007065 15125143417 0013274 0 ustar 00 NAME Mock::Config - temporarily set Config or XSConfig values VERSION Version 0.02 SYNOPSIS XSConfig is readonly, so workaround that. use Mock::Config d_fork => 0, perl_patchlevel => ''; The importer works only dynamically, not lexically yet. use Mock::Config; Mock::Config->import(startperl => ''); print $Config{startperl}, ' mocked to empty'; Mock::Config->unimport; SUBROUTINES import Set pair of Config values, even for the readonly XSConfig implementation, as used in cperl. It does not store the mocked overrides lexically, just dynamically. unimport This is unstacked and not lexical. It undoes all imported Config values at once. AUTHOR Reini Urban, "<rurban at cpan.org>" BUGS Please report any bugs or feature requests at <https://github.com/perl11/Mock-Config/issues>. We will be notified, and then you'll automatically be notified of progress on your request as we make changes. SUPPORT You can find documentation for this module with the perldoc command. perldoc Mock::Config You can also look for information at: * RT: CPAN's request tracker (report bugs here) <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mock-Config> * AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/Mock-Config> * CPAN Ratings <http://cpanratings.perl.org/d/Mock-Config> * Search CPAN <http://search.cpan.org/dist/Mock-Config/> ACKNOWLEDGEMENTS LICENSE AND COPYRIGHT Copyright 2016 cPanel Inc. This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: <http://www.perlfoundation.org/artistic_license_2_0> Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. var/log/README 0000644 00000002020 15125146136 0006773 0 ustar 00 You are looking for the traditional text log files in /var/log, and they are gone? Here's an explanation on what's going on: You are running a systemd-based OS where traditional syslog has been replaced with the Journal. The journal stores the same (and more) information as classic syslog. To make use of the journal and access the collected log data simply invoke "journalctl", which will output the logs in the identical text-based format the syslog files in /var/log used to be. For further details, please refer to journalctl(1). Alternatively, consider installing one of the traditional syslog implementations available for your distribution, which will generate the classic log files for you. Syslog implementations such as syslog-ng or rsyslog may be installed side-by-side with the journal and will continue to function the way they always did. Thank you! Further reading: man:journalctl(1) man:systemd-journald.service(8) man:journald.conf(5) http://0pointer.de/blog/projects/the-journal.html etc/rc.d/init.d/README 0000644 00000002211 15125200022 0010173 0 ustar 00 You are looking for the traditional init scripts in /etc/rc.d/init.d, and they are gone? Here's an explanation on what's going on: You are running a systemd-based OS where traditional init scripts have been replaced by native systemd services files. Service files provide very similar functionality to init scripts. To make use of service files simply invoke "systemctl", which will output a list of all currently running services (and other units). Use "systemctl list-unit-files" to get a listing of all known unit files, including stopped, disabled and masked ones. Use "systemctl start foobar.service" and "systemctl stop foobar.service" to start or stop a service, respectively. For further details, please refer to systemctl(1). Note that traditional init scripts continue to function on a systemd system. An init script /etc/rc.d/init.d/foobar is implicitly mapped into a service unit foobar.service during system initialization. Thank you! Further reading: man:systemctl(1) man:systemd(1) http://0pointer.de/blog/projects/systemd-for-admins-3.html https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities usr/share/doc/libmd/README 0000644 00000001432 15125426474 0011205 0 ustar 00 libmd - Message Digest functions from BSD systems This library provides message digest functions found on BSD systems either on their libc or libmd libraries and lacking on others like GNU systems, thus making it easier to port projects with strong BSD origins, without needing to embed the same code over and over again on each project. Website ------- The project website can be found at: <https://www.hadrons.org/software/libmd/> Releases -------- <https://archive.hadrons.org/software/libmd/> Source Repository ----------------- <https://git.hadrons.org/cgit/libmd.git> Mailing List ------------ The subscription interface and web archives can be found at: <https://lists.freedesktop.org/mailman/listinfo/libbsd> The mail address is: libbsd@lists.freedesktop.org etc/fonts/conf.d/README 0000644 00000001723 15125456666 0010522 0 ustar 00 conf.d/README Each file in this directory is a fontconfig configuration file. Fontconfig scans this directory, loading all files of the form [0-9][0-9]*.conf. These files are normally installed in /usr/share/fontconfig/conf.avail and then symlinked here, allowing them to be easily installed and then enabled/disabled by adjusting the symlinks. The files are loaded in numeric order, the structure of the configuration has led to the following conventions in usage: Files beginning with: Contain: 00 through 09 Font directories 10 through 19 system rendering defaults (AA, etc) 20 through 29 font rendering options 30 through 39 family substitution 40 through 49 generic identification, map family->generic 50 through 59 alternate config file loading 60 through 69 generic aliases, map generic->family 70 through 79 select font (adjust which fonts are available) 80 through 89 match target="scan" (modify scanned patterns) 90 through 99 font synthesis usr/share/doc/libpaper/README 0000644 00000002755 15125501461 0011713 0 ustar 00 The paper library and accompanying files are intended to provide a simple way for applications to take actions based on a system- or user-specified paper size. This release is quite minimal, its purpose being to provide really basic functions (obtaining the system paper name and getting the height and width of a given kond of paper) that applications can immediately integrate. A more complete library, using a capabilities file for papers (giving, in addition to the size, informations like paper weigth, color, etc) will be released later. See the sources for paperconf(1) in src/paper.c for how to use the library. Adding new paper sizes ====================== If a paper format is missing, one need to add it to lib/paperspecs. The format of this file is one paper format per line, with the name of the format, the width and height of the format separated with space. You may add an option measurement unit among in, ft, pt, m, dm, cm, mm or you may leave the default unit of "point". By defaults the width and height are specified in the "point" unit, which is 1/72 inch (2.54 cm). This is the A4 entry: a4 210 297 mm that was previously written as a4 595 842 The sizes here are 595 points / 72 points pr inch * 2.54 cm per inch = 20.99 cm and 842/72*2.54 = 29.70 cm. The A4 format is 210x297 mm so this is a good approximation. (Source: <URL:http://en.wikipedia.org/wiki/A4_paper_size>) Copyright (C) Yves Arrouye <yves@debian.org>, 1996 Adrian Bunk <bunk@fs.tum.de> , 2000 usr/share/doc/m4/README 0000644 00000011073 15125513706 0010433 0 ustar 00 GNU `m4' is an implementation of the traditional Unix macro processor. It is mostly SVR4 compatible, although it has some extensions (for example, handling more than 9 positional parameters to macros). `m4' also has built-in functions for including files, running shell commands, doing arithmetic, etc. Autoconf needs GNU `m4' for generating `configure' scripts, but not for running them. GNU `m4' was originally written by René Seindal, from Denmark. This release is considered stable. If GNU `m4' is meant to serve GNU `autoconf', beware that `m4' should be fully installed *prior to* configuring `autoconf' itself. Likewise, if you intend on hacking GNU `m4' from git, the bootstrap process requires that you first install a released copy of GNU `m4'. If you are just trying to build `m4' from a released tarball, you should not normally need to run `./bootstrap' or `autoreconf'; just go ahead and start with `./configure'. If you are trying to build `m4' from git, more information can be found in the version-control-only file HACKING. M4 has an optional dependency on the libsigsegv library: https://www.gnu.org/software/libsigsegv/ If the library has not been installed in the standard location, you can use `./configure --with-libsigsegv-prefix=/path/to/dir', to make the build of `m4' use /path/to/dir/include/sigsegv.h as appropriate. The use of this library is optional; the only difference in having it available is that it increases the number of platforms where `m4' can correctly distinguish stack overflow from an internal bug. It is recommended that you use version 2.9 or newer. In the subdirectory `examples' you will find various m4 files, ranging from trivial test files to rather advanced macros. If you intend to use m4 seriously, you might find useful material down there. See file `BACKLOG' for a summary of pending mail and articles. See file `COPYING' for copying conditions. Note that M4 is distributed under the GNU Public License version 3 or later. Some files in the distribution are copied from the
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????