NAME

Mir::FileHandler - An Mir module to handle files and folders...

VERSION

Version 0.03

SYNOPSIS

use Mir::FileHandler;

# the oo way...
# get a new FileHandler obj for the passed root directory
my $o = Mir::FileHandler->new( 
    path => $path, # root folder to start with 
);

# get plain files list inside the root directory
my $list = $o->plainfiles(); # or pass a path in input

# get plain files list from folder and sub-folders
my $list = $o->plainfiles_recursive( $path, $suffix, \&found );

# Traverses a directory tree and exec code for each file
$o->dir_walk(
    path => $path,
    code => $code,
);

# Traverses a directory tree and exec code for each file
# Stops after max success code execution
# the sub pointed by $code has to return 1 in
# case of success
# if cached_dir is set, at each iteration starts from 
# what stored in cache, if something has been stored,
# otherwise starts from path
$o->clear_cache(); # to clear current dir stored in cache
$o->dir_walk_max(
    code => $code, # not mandatory, code to exec for each file found
    max  => $max  # not mandatory, max files successfully processed
);

EXPORT

plainfiles
plainfiles_recursive

SUBROUTINES/METHODS

plainfiles

INPUT

$path: path to look for (not mandatory, eventually takes the
        one passed at construction time)

OUTPUT

An ArrayRef

DESCRIPTION

Returns the list of folder plain files.

_pf

INPUT

$path: the path to look for docs

OUTPUT

A sorted list of docs.

DESCRIPTION

Private function. Returns the sorted list of regular files in current folder.

_get_path_from_cache

INPUT

None

OUTPUT

The cache path or undef

DESCRIPTION

Tries to retrieve a current path cached for the root one or returns undef

dir_walk - traverses recursively a folder

INPUT

An hash with keys: code: a coderef to apply to each file

OUTPUT

-1 if root file or folder are not existent, else the number of valid files.

DESCRIPTION

Traverse a directory, triggering a sub for each file found. The sub should return 1 if file is good, 0 otherwise. It is meant to recursively process a folder in one shot. This is the minimal logic to traverse a tree, for added, features look at dir_walk_max.

_walk

INPUT

$top: subtree root
$code: code to execute against each valid file
$count: number of valid files till now...

OUTPUT

The number of valid files.

DESCRIPTION

Traverse the subtree.

dir_walk_max - traverses recursively a folder, stops after max valid files found or all tree has been traversed

INPUT

An hash with keys: code: a coderef to apply to max: max number of items to evaluate

OUTPUT

-1 if root file or folder are not existent, else the number of valid files.

DESCRIPTION

Traverse a directory, triggering a sub for each file found. The sub should return 1 if file is good, 0 otherwise. The method stops when all files are consumed or max number of good files is reached.

_walk_max

INPUT

root : the root folder to start with count : number of valid items processed rel_path : the relative path from root max : max number of valid items code : code to run against each item

OUTPUT

The number of valid items processed

DESCRIPTION

Inner loop to analize each item of the tree. it calls recursively itself for each sub-tree. Ends when 1 of these conditions is met: - no more files found - max number of valid items reached this number is set to be 10 times the max number of valid items.

plainfiles_recursive

INPUT

$path:      a path to start from.
$avoid:     arrayref con lista risorse da evitare
$suffix:    arrayref con lista suffissi da processare
$found:     ref sub callback per ogni risorsa

OUTPUT

An arrayref.

DESCRIPTION

Returns recursively the list of all files from passed folder.

plainfiles_recursive_as_hash

INPUT

$path : root path (not mandatory if already passed at 
        construction time)

OUTPUT

An HashRef.

DESCRIPTION

Recursively collects files in an hash indexed by file suffix.

plainfiles_recursive_of_type

INPUT

@types: list of valid file suffixes

OUTPUT

An ArrayRef or undef in case of errors.

DESCRIPTION

Recursively collects all files with valid suffixes

process_dir

INPUT

$dir    : dir to start with
$suffix : arrayref of valid file suffixes
$depth  : depth in processing subdirs

OUTPUT

An arrayref

DESCRIPTION

Workflow:
get a single dir as input and the level of recursions
get the list of valid dir files and process them
get the list of dir direct subdirs
depth-- 
if depth > 0
    call process_dir foreach subdir

AUTHOR

Marco Masetti, <marco.masetti at softeco.it>

BUGS

Please report any bugs or feature requests to bug-ishare-filehandler at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mir-FileHandler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Mir::FileHandler

LICENSE AND COPYRIGHT

Copyright 2013 Marco Masetti.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.