App-Pods2Site
view release on metacpan or search on metacpan
lib/App/Pods2Site/PodCopier.pm view on Meta::CPAN
# copy all found pods into a work tree, so the HTML generation
# has a good base to work from
#
sub __copyPods
{
my $self = shift;
my $args = shift;
my $podFinder = shift;
# keep running tally of groups and associated pods
#
my @workGroups;
# set up some progress feedback
#
my $spinner = createSpinner($args);
# copy pods from each group
#
my $count = 0;
my $groups = $podFinder->getGroups();
foreach my $group (@$groups)
{
my $groupName = $group->{name};
my $pods = $group->{pods};
my %podInfo;
foreach my $pod (@$pods)
{
my $podName = $pod->{name};
my $inFile = $pod->{path};
my $podFile = $self->__copy($inFile, $podName, $groupName, $args);
$podInfo{$podName} = { podfile => $podFile, htmlfile => undef };
$spinner->(++$count);
}
push(@workGroups, { group => $groupName, podinfo => \%podInfo });
}
$self->{workgroups} = \@workGroups;
}
sub __copy
{
my $self = shift;
my $infile = shift;
my $name = shift;
my $group = shift;
my $args = shift;
# copy every 'name' infile to outfile, for simplicity, always use the '.pod' extension
#
my $podname = $name;
$podname =~ s#::#/#g;
my $outfile = slashify("$self->{podroot}/$group/$podname.pod");
# we're copying in a specific order, and it's possible
# a pod with the same name might come from two different categories
# if so, only copy the first, but make sure the copy retains the mtime
# from the infile, so the HTML gen can avoid regenerating
#
my $mtimeInfile = (stat($infile))[9];
if (!-e $outfile)
{
my $outfileDir = dirname($outfile);
(!-d $outfileDir ? make_path($outfileDir) : 1) || die ("Failed to create directory '$outfileDir': $!\n");
copy($infile, $outfile) || die("Failed to copy $infile => $outfile: $!\n");
utime($mtimeInfile, $mtimeInfile, $outfile);
}
$self->{count}++;
print "Copied '$infile' => '$outfile'\n" if $args->isVerboseLevel(3);
return $outfile;
}
1;
( run in 0.534 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )