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 );
33 #initialize template toolkit
35 my $template = Template->new;
37 foreach my $file (@files) {
38 next if $file =~ /^$out_dir/;
39 next if $file =~ /$0$/;
40 if ($file =~ /\.tt2$/) {
42 $template->process($file, undef, \$output)
43 || die "Could not process file \"$file\": $!";
45 my ($name,$path,$suffix) = fileparse($file,qw (.tt2));
46 make_path("$tempdir/$path") unless -d "$tempdir/$path";
47 open (my $fh, '>', "$tempdir/$path/$name")
48 or die "Could not write to $file: $!";
52 fcopy ($file, "$tempdir/$file") or die "Could not copy $file to $tempdir/$file: $!";
58 dirmove ($out_dir, $out_dir . ".bak")
59 or die "Could not move $out_dir to $out_dir.bak: $!";
61 if (! dirmove ($tempdir, "$out_dir")) {
62 warn "Could not move $tempdir to $out_dir: $!";
64 remove_tree($out_dir);
65 dirmove ($out_dir . ".bak", $out_dir);
67 remove_tree($out_dir . ".bak");