8 use File::Path qw(make_path remove_tree);
9 use File::Basename qw (fileparse dirname);
10 use File::Copy::Recursive qw(fcopy dirmove);
11 use File::Temp qw (tempdir);
13 my $out_dir = shift || "out/";
17 #rule to match git directorys
18 my $git = File::Find::Rule->directory
24 my $file_rule = File::Find::Rule->file();
27 my @files = File::Find::Rule->or( $git, $file_rule )
31 my $tempdir = tempdir( CLEANUP => 1 );
32 make_path("$tempdir/out") or die "Could not create $tempdir/out: $!";
35 #initialize template toolkit
37 my $template = Template->new;
39 foreach my $file (@files) {
40 next if $file =~ /^$out_dir/;
41 next if $file =~ /$0$/;
42 if ($file =~ /\.tt2$/) {
44 $template->process($file, undef, \$output)
45 || die "Could not process file \"$file\": $!";
47 my ($name,$path,$suffix) = fileparse($file,qw (.tt2));
48 make_path("$tempdir/out/$path") unless -d "$tempdir/out/$path";
49 open (my $fh, '>', "$tempdir/out/$path/$name")
50 or die "Could not write to $file: $!";
54 fcopy ($file, "$tempdir/out/$file") or die "Could not copy $file to $tempdir/out/$file: $!";
60 dirmove ($out_dir, $out_dir . ".bak")
61 or die "Could not move $out_dir to $out_dir.bak: $!";
63 if (! dirmove ("$tempdir/out", "$out_dir")) {
64 warn "Could not move $tempdir/out to $out_dir: $!";
66 remove_tree($out_dir);
67 dirmove ($out_dir . ".bak", $out_dir);
69 remove_tree($out_dir . ".bak");