File-Tasks
view release on metacpan or search on metacpan
execute $dir
Executes the File::Tasks. This will create, modify or remove files as
described in the Tasks.
Due to the delicate and somewhat complex nature of the installation, you
almost certainly will want to do a test run with "<-"test($dir)>> before
the live call.
Returns true if completed successfully, or "undef" otherwise.
overlay $Under, $Over
To keep complexity down, a great way of generating File::Tasks objects
that will "overwrite" a previous installation is to do it in two parts.
# Create a script to remove the old installation
my $Old = File::Tasks->new;
$Old->remove_dir($dir);
# Script for a fresh install spat out by some module
my $Install = My::Module->build->Script;
# Overlay the new install over the old removal to create
# a combined script that will "shift" the current files as needed.
my $Script = $Old->overlay($Install);
Where this gets really cool is that if the new file is the same as the
old file, the Task will be optimised away.
This means that if the underlying data for a process changes, and you
rerun a generator of some sort, the only output files that are touched
are the ones that will actually change as a result of the underlying
data changing.
Given two File::Tasks objects, will create and return a new Script that
represents the combination of the two. Returns "undef" on error.
The + operator is also effectively overloaded to this method
# The explicit way
my $Script = $Old->overlay($Install);
# Via the overload
my $Script = $Old + $Install;
TO DO
- Much more detailed unit testing
- Add various caching options
SUPPORT
lib/File/Tasks.pm view on Meta::CPAN
use strict;
use Clone ();
use Params::Util '_INSTANCE';
use Params::Coerce ();
use File::Tasks::Provider ();
use File::Tasks::Add ();
use File::Tasks::Edit ();
use File::Tasks::Remove ();
use constant 'FFR' => 'File::Find::Rule';
use overload 'bool' => sub () { 1 };
use overload '+' => '_overlay';
use vars qw{$VERSION};
BEGIN {
$VERSION = '0.07';
}
lib/File/Tasks.pm view on Meta::CPAN
1;
}
#####################################################################
# Higher Order Methods
sub overlay {
my $self = Clone::clone shift;
my $other = Params::Coerce::coerce('File::Tasks', shift) or return undef;
foreach my $Task ( $other->tasks ) {
my $Current = $self->task($Task->path);
unless ( $Current ) {
$self->set($Current) or return undef;
next;
}
if ( $Task->type eq 'add' ) {
if ( $Current->type eq 'add' ) {
lib/File/Tasks.pm view on Meta::CPAN
$self->{tasks}->{$Task} = $Task;
} else {
# Nothing to do
}
}
}
$self;
}
# A thin wrapper to handle the way overloaded arguments are provided
sub _overlay {
my $left = _INSTANCE(shift, 'File::Tasks') ? shift : return undef;
my $right = Params::Coerce::coerce('File::Tasks', shift) or return undef;
($left, $right) = ($right, $left) if $_[0];
$left->overlay($right);
}
#####################################################################
# Coercion Support
# From an entire builder
lib/File/Tasks.pm view on Meta::CPAN
Executes the File::Tasks. This will create, modify or remove files as
described in the Tasks.
Due to the delicate and somewhat complex nature of the installation, you
almost certainly will want to do a test run with C<<->test($dir)>> before
the live call.
Returns true if completed successfully, or C<undef> otherwise.
=head2 overlay $Under, $Over
To keep complexity down, a great way of generating File::Tasks objects
that will "overwrite" a previous installation is to do it in two parts.
# Create a script to remove the old installation
my $Old = File::Tasks->new;
$Old->remove_dir($dir);
# Script for a fresh install spat out by some module
my $Install = My::Module->build->Script;
# Overlay the new install over the old removal to create
# a combined script that will "shift" the current files as needed.
my $Script = $Old->overlay($Install);
Where this gets really cool is that if the new file is the same as the
old file, the Task will be optimised away.
This means that if the underlying data for a process changes, and you
rerun a generator of some sort, the only output files that are touched
are the ones that will actually change as a result of the underlying
data changing.
Given two File::Tasks objects, will create and return a new Script that
represents the combination of the two. Returns C<undef> on error.
The + operator is also effectively overloaded to this method
# The explicit way
my $Script = $Old->overlay($Install);
# Via the overload
my $Script = $Old + $Install;
=head1 TO DO
- Much more detailed unit testing
- Add various caching options
tasks=method
paths=method
add=method
edit=method
remove=method
remove_dir=method
set=method
clashes=method
test=method
execute=method
overlay=method
[File::Tasks::Task]
type=method
new=method
path=method
test=method
execute=method
[File::Tasks::Add]
File::Tasks::Task=isa
( run in 0.626 second using v1.01-cache-2.11-cpan-49f99fa48dc )