The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Hub::Util -

SYNOPSIS

EXPORTS

Nothing exported by default

Exported upon request

RE_ABSTRACT_KEY, RE_ABSTRACT_ADDR, $VALUE_ALL, $VALUE_ALL_REC, $PATTERN_QUERY, $PATTERN_QUERY_SUBKEY, $PATTERN_QUERY_VALUE, $PATTERN_QUERY_RANGE, $PATTERN_QUERY_KEY, %TYPEOF_ALIASES, FS, is_abstract_key, is_abstract_addr, curry, typeof, addr_shift, addr_pop, addr_normalize, addr_parent, addr_name, addr_basename, addr_split, addr_join, addr_ext, addr_base, path_shift, path_pop, path_push, path_normalize, path_parent, path_name, path_split, path_join, path_ext, path_is_absolute, path_basename, fs_handle, file_read, file_read_binary, file_read_crown, file_create, file_write, file_write_binary, file_copy, file_move, file_remove, dir_read, dir_create, dir_copy, dir_copy_contents, dir_is_system, dir_move, dir_remove, dir_remove_contents

:all

RE_ABSTRACT_KEY, RE_ABSTRACT_ADDR, $VALUE_ALL, $VALUE_ALL_REC, $PATTERN_QUERY, $PATTERN_QUERY_SUBKEY, $PATTERN_QUERY_VALUE, $PATTERN_QUERY_RANGE, $PATTERN_QUERY_KEY, %TYPEOF_ALIASES, FS, is_abstract_key, is_abstract_addr, curry, typeof, addr_shift, addr_pop, addr_normalize, addr_parent, addr_name, addr_basename, addr_split, addr_join, addr_ext, addr_base, path_shift, path_pop, path_push, path_normalize, path_parent, path_name, path_split, path_join, path_ext, path_is_absolute, path_basename, fs_handle, file_read, file_read_binary, file_read_crown, file_create, file_write, file_write_binary, file_copy, file_move, file_remove, dir_read, dir_create, dir_copy, dir_copy_contents, dir_is_system, dir_move, dir_remove, dir_remove_contents

DEPENDENCIES

This module requires these other modules and libraries:

    Error::Simple
    File::Copy
    IO::File
    Parse::StringTokenizer
    Error::Programatic
    Perl::Module
    Fcntl
    Exporter
    Encode
    Data::Hub::Address
    IO::Dir

DESCRIPTION

EXAMPLES

This example will not abort:

  # Load this module
  use Data::Hub::Util qw(:all);

PUBLIC INTERFACE

is_abstract_key

Is the key abstract (produces a subset)

TODO The regex RE_ABSTRACT_KEY uses an error-prone search for | and * (these are allowed in hashfile key names.

is_abstract_addr

Does the address contain an abstract key

curry

Add the courier magic to the provided reference

This example:

  curry({a=>{b=>'c'}})->get('/a/b');

will return:

  c

typeof

Return the logical type for the given file-system or data structure

This example:

  typeof('foo.bar', {});

will return:

  data-hash

This example:

  typeof('/with/path/foo.bar', []);

will return:

  data-array

This example:

  typeof('foo.bar', 'baz');

will return:

  data-scalar-bar

addr_shift

Return the next token and trim the address

This example:

  my $addr = '/one/two/{/i/am/three}/four';
  join(':', addr_shift($addr), addr_shift($addr), addr_shift($addr),
  addr_shift($addr)); 

will return:

  one:two:{/i/am/three}:four

addr_pop

Return the last token and trim the address

This example:

  my $addr = '/one/two';
  my $last = addr_pop($addr);
  "$last,$addr"

will return:

  two,/one

addr_normalize

Normalize form of the given address

See also "_normalize"

This example:

  addr_normalize('/');

will return:

  /

This example:

  addr_normalize('/a/');

will return:

  /a

This example:

  addr_normalize('/a/b/..');

will return:

  /a

This example:

  addr_normalize('/a/../b');

will return:

  /b

This example:

  addr_normalize('/a/../../b');

will return:

  /b

This example:

  addr_normalize('/a/.../b');

will return:

  /a

This example:

  addr_normalize('/a/.../');

will return:

  /a

This example:

  addr_normalize('/a/...');

will return:

  /a

This example:

  addr_normalize('/a/.../..');

will return:

  /a

This example:

  addr_normalize('/a/../...');

will return:

  /

addr_parent

Return the parent of the given address

This example will not return a defined value:

  addr_parent();

This example will not return a defined value:

  addr_parent('');

This example:

  addr_parent('/');

will return:

  /

This example:

  addr_parent('/a');

will return:

  /

This example:

  addr_parent('/a/b/..');

will return:

  /

This example:

  addr_parent('a/b/');

will return:

  a

This example:

  addr_parent('a/b.c');

will return:

  a

addr_name

Return the name part of an address

This example will not return a defined value:

  addr_name('');

This example:

  addr_name('/');

will return:

This example:

  addr_name('/a');

will return:

  a

This example:

  addr_name('/a/b/..');

will return:

  a

This example:

  addr_name('a/b/');

will return:

  b

This example:

  addr_name('a/b.c');

will return:

  b.c

addr_split

Return each part of an address

This example:

  scalar(addr_split(''));

will return:

  0

This example:

  join ' ', addr_split('/');

will return:

This example:

  join ' ', addr_split('/a');

will return:

  a

This example:

  join ' ', addr_split('/a/b/..');

will return:

  a

This example:

  join ' ', addr_split('a/b/');

will return:

  a b

This example:

  join ' ', addr_split('a/b.c');

will return:

  a b.c

addr_join

Normalize form of the given address

See also "_normalize"

This example:

  addr_join('/');

will return:

  /

This example:

  addr_join('/a', '/');

will return:

  /a

This example:

  addr_join('/a/', 'b/..');

will return:

  /a

This example:

  addr_join('/a/..', '/b');

will return:

  /b

This example:

  addr_join('/a/../', '../b');

will return:

  /b

This example:

  addr_join('/a/.../', 'b');

will return:

  /a

This example:

  addr_join('/a/', '.../');

will return:

  /a

This example:

  addr_join('/a/', '...');

will return:

  /a

This example:

  addr_join('/a/', 'b/');

will return:

  /a/b

This example:

  addr_join('/a/', 'b');

will return:

  /a/b

This example:

  addr_join('/a', '/b');

will return:

  /a/b

This example:

  addr_join('/a', 'b');

will return:

  /a/b

This example:

  addr_join('/a', 'b', 'c');

will return:

  /a/b/c

addr_ext

Return the extension part of the given address

This example will not return a defined value:

  addr_ext(undef);

This example:

  addr_ext('foo.txt');

will return:

  txt

This example:

  addr_ext('/foo.txt');

will return:

  txt

This example:

  addr_ext('./foo.txt');

will return:

  txt

This example:

  addr_ext('../foo.txt');

will return:

  txt

This example:

  addr_ext('/foo/foo.txt');

will return:

  txt

This example:

  addr_ext('/foo.bar.txt');

will return:

  txt

This example:

  addr_ext('/foo/bar.');

will return:

This example will not return a defined value:

  addr_ext('/foo/bar');

This example will not return a defined value:

  addr_ext('.metadata');

This example:

  addr_ext('.metadata.bak');

will return:

  bak

addr_basename

Return the name at the given address without its extension

This example will not return a defined value:

  addr_basename(undef);

This example will not return a defined value:

  addr_basename('/');

This example:

  addr_basename('foo.txt');

will return:

  foo

This example:

  addr_basename('foo.txt/');

will return:

  foo

This example:

  addr_basename('/foo.txt');

will return:

  foo

This example:

  addr_basename('./foo.txt');

will return:

  foo

This example:

  addr_basename('../foo.txt');

will return:

  foo

This example:

  addr_basename('/foo/foo.txt');

will return:

  foo

This example:

  addr_basename('/foo.bar.txt');

will return:

  foo.bar

This example:

  addr_basename('/foo/bar.');

will return:

  bar

This example:

  addr_basename('/foo/bar');

will return:

  bar

This example will not return a defined value:

  addr_basename('.metadata');

This example:

  addr_basename('.metadata.bak');

will return:

  .metadata

addr_base

Return the base (known part) of the given address

This example:

  addr_base('/a/b/{d}');

will return:

  /a/b

This example:

  addr_base('/a/b/d');

will return:

  /a/b/d

path_shift

Return the next token and trim the path

This example:

  my $path = '/one/two/../four';
  join(':', path_shift($path), path_shift($path), path_shift($path),
  path_shift($path)); 

will return:

  one:two:..:four

path_pop

Return the last token and trim the path

This example:

  my $path = '/one/two';
  my $last = path_pop($path);
  "$last,$path"

will return:

  two,/one

path_push

Push a token on to the path

This example:

  my $path = '/one/two';
  my $count = path_push($path, 'three');
  "$path"

will return:

  /one/two/three

path_split

Return each part of a path

This example:

  path_split('');

will return:

  0

This example:

  join ' ', path_split('/');

will return:

This example:

  join ' ', path_split('/a');

will return:

  a

This example:

  join ' ', path_split('/a/b/..');

will return:

  a

This example:

  join ' ', path_split('a/b/');

will return:

  a b

This example:

  join ' ', path_split('a/b.c');

will return:

  a b.c

path_basename

Return the name part of the given path without its extension

This example will not return a defined value:

  path_basename(undef);

This example:

  path_basename('foo.txt');

will return:

  foo

This example:

  path_basename('/foo.txt');

will return:

  foo

This example:

  path_basename('./foo.txt');

will return:

  foo

This example:

  path_basename('../foo.txt');

will return:

  foo

This example:

  path_basename('/foo/foo.txt');

will return:

  foo

This example:

  path_basename('/foo.bar.txt');

will return:

  foo.bar

This example:

  path_basename('/foo/bar.');

will return:

  bar

This example:

  path_basename('/foo/bar');

will return:

  bar

This example:

  path_basename('.bashrc');

will return:

  .bashrc

This example:

  path_basename('.bashrc.tmp');

will return:

  .bashrc

This example:

  path_basename('/no-dots');

will return:

  no-dots

path_ext

Return the extension part of the given path

This example will not return a defined value:

  path_ext(undef);

This example:

  path_ext('foo.txt');

will return:

  txt

This example:

  path_ext('/foo.txt');

will return:

  txt

This example:

  path_ext('./foo.txt');

will return:

  txt

This example:

  path_ext('../foo.txt');

will return:

  txt

This example:

  path_ext('/foo/foo.txt');

will return:

  txt

This example:

  path_ext('/foo.bar.txt');

will return:

  txt

This example:

  path_ext('/foo/bar.');

will return:

This example will not return a defined value:

  path_ext('/foo/bar');

This example will not return a defined value:

  path_ext('.bashrc');

This example:

  path_ext('.bashrc.tmp');

will return:

  tmp

This example will not return a defined value:

  path_ext('/no-dots');

path_normalize

Normalize form of the given path

See also "_normalize"

This example:

  path_normalize('/');

will return:

  /

This example:

  path_normalize('/a/');

will return:

  /a

This example:

  path_normalize('/a/b/..');

will return:

  /a

This example:

  path_normalize('/a/../a');

will return:

  /a

This example:

  path_normalize('/a/../../a');

will return:

  /a

This example:

  path_normalize( "../../w/b/../s/x" );

will return:

  ../../w/s/x

This example:

  path_normalize( "u/n/w/" );

will return:

  u/n/w

This example:

  path_normalize( "u/../w/b/../s" );

will return:

  w/s

This example:

  path_normalize( "u//n" );

will return:

  u/n

This example:

  path_normalize( "u//n/./f" );

will return:

  u/n/f

This example:

  path_normalize( "http://t/u//n" );

will return:

  http://t/u/n

This example:

  path_normalize( '/a/b/c/../../../d/e/f' );

will return:

  /d/e/f

This example:

  path_normalize( './a' );

will return:

  ./a

This example:

  path_normalize( '/./a' );

will return:

  /a

path_parent

Return the parent of the given path

This example will not return a defined value:

  path_parent('');

This example:

  path_parent('/');

will return:

  /

This example:

  path_parent('/a');

will return:

  /

This example:

  path_parent('/a/b/..');

will return:

  /

This example:

  path_parent('a');

will return:

This example:

  path_parent('a/b/');

will return:

  a

This example:

  path_parent('a/b.c');

will return:

  a

This example:

  path_parent('../../a');

will return:

  ../..

path_name

Return the name part of a path

This example will not return a defined value:

  path_name('');

This example:

  path_name('/');

will return:

This example:

  path_name('/a');

will return:

  a

This example:

  path_name('/a/b/..');

will return:

  a

This example:

  path_name('a/b/');

will return:

  b

This example:

  path_name('a/b.c');

will return:

  b.c

path_is_absolute

Is the path an absolute path

This example will return true:

  path_is_absolute('/a');

This example will return true:

  path_is_absolute('A:/b');

This example will return true:

  path_is_absolute('/a/b');

This example will return true:

  path_is_absolute('http://a');

This example will return true:

  path_is_absolute('svn+ssh://a.b');

This example will return false:

  path_is_absolute('');

This example will return false:

  path_is_absolute('a/b');

This example will return false:

  path_is_absolute('a:\\b');

This example will return false:

  path_is_absolute('a/../b');

This example will return false:

  path_is_absolute('../a');

This example will return false:

  path_is_absolute('./a');

This example will return false:

  path_is_absolute('svn+ssh//a.b');

This example will return false:

  path_is_absolute('1://');

This example will return false:

  path_is_absolute('+://');

dir_read

Return directory entries

file_read

Read file contents

file_read_binary

Read file contents (binary)

file_create

Create an empty file if none exists

file_write

Write contents to file

where:

  @contents           Items may be scalars or scalar references

returns:

  1 when successful
  dies if a handle cannot be obtained

file_write_binary

Write contents to file (binary)

where:

  @contents           Items may be scalars or scalar references

returns:

  1 when successful
  dies if a handle cannot be obtained

file_read_crown

Return the first line of a file

fs_handle

Return a file or directory handle

where:

  $path           # Absolute or relative file-system path
  $mode   r|w|rw  # Read or write access (default 'r')

dir_create

Create directory including parents

file_copy

Copy a file

See also: File::Copy::copy

file_move

Move a file

See also: File::Copy::move

dir_copy

Copy a directory recursively

dir_copy_contents

Copy a directory's contents recursively

dir_remove_contents

Remove a directories contents

dir_is_system

The directory is a system folder, such as '.svn'

This example will return true:

  # normal usage
  dir_is_system('.svn', '/tmp');

This example will return true:

  # normal usage
  dir_is_system('.git', '/tmp');

This example will return false:

  # case sensitive
  dir_is_system('.Svn', '/tmp');

This example will not return a defined value:

  # undefined test
  dir_is_system(undef, undef);

dir_move

Move a directory

See also: File::Copy::move

file_remove

Remove a file

dir_remove

Remove a directory recursively

PACKAGE INTERNALS

FS

Return the package name for the given file-system class

This example:

  FS('Node');

will return:

  Data::Hub::FileSystem::Node

_normalize

Implementation method for addr_normalize and path_normalize

AUTHORS

    Ryan Gies <ryangies@cpan.org>

COPYRIGHT

    Copyright (C) 2014-2016 by Ryan Gies. All rights reserved.
    Copyright (C) 2006-2013 by Livesite Networks, LLC. All rights reserved.
    Copyright (C) 2000-2005 by Ryan Gies. All rights reserved.
    Redistribution and use in source and binary forms, with or without 
    modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, 
    this list of conditions and the following disclaimer.
    * The origin of this software must not be misrepresented; you must not 
    claim that you wrote the original software. If you use this software in a 
    product, an acknowledgment in the product documentation would be 
    appreciated but is not required.
    * Altered source versions must be plainly marked as such, and must not be 
    misrepresented as being the original software.
    * The name of the author may not be used to endorse or promote products 
    derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 
    WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
    EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
    OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
    OF SUCH DAMAGE.
    To the best of our knowledge, no patented algorithms have been used. However, we
    do not have the resources to carry out a patent search, and therefore cannot 
    give any guarantee of the above statement.