--- a/.hgignore Tue Dec 29 21:40:48 2015 +0100
+++ b/.hgignore Tue Dec 29 22:59:42 2015 +0100
@@ -1,5 +1,5 @@
^.htaccess
-^var/version.tt
+^templates.var/version.tt
^blib/
^Build$
^_build/
--- a/Build.PL Tue Dec 29 21:40:48 2015 +0100
+++ b/Build.PL Tue Dec 29 22:59:42 2015 +0100
@@ -5,4 +5,18 @@
dist_version_from => 'lib/Once.pm',
dist_abstract => 'once downloader',
script_files => [qw(bin/once)],
+ share_dir => [qw(templates)],
+ requires => {
+ 'perl' => '5.0.18',
+ 'File::MimeInfo' => 0,
+ 'Template' => 0,
+ 'experimental' => 0,
+ },
)->create_build_script;
+
+# create the var.tt to be included
+mkdir 'templates.var' or -d 'templates.var' or die "templates.var: $!";
+chomp(my $version = `hg log -r . --template '{latesttag}-{latesttagdistance}-{node|short}\n'`);
+open(my $o, '>', $_ = 'templates.var/version.tt') or die "Can't open $_: $!\n";
+print $o qq{[% vcs.version = "$version"; %]\n};
+
--- a/Makefile Tue Dec 29 21:40:48 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-var/version.tt: once.pl
- # $@
- @-mkdir -p $(dir $@)
- @echo '[% vcs.version = "'`hg describe`'" %]' > $@
--- a/bin/once Tue Dec 29 21:40:48 2015 +0100
+++ b/bin/once Tue Dec 29 22:59:42 2015 +0100
@@ -39,16 +39,19 @@
use IO::File;
use CGI qw(param upload header request_method url redirect);
use CGI::Carp qw(fatalsToBrowser);
-use FindBin qw($RealBin);
+use FindBin qw($RealBin $Bin);
use File::Basename;
use File::Path qw(remove_tree make_path);
use File::Spec::Functions;
+use File::ShareDir qw(dist_dir);
use File::MimeInfo qw(mimetype);
use Cwd qw(getcwd realpath);
use Digest::MD5 qw(md5_hex md5);
use Template;
use experimental qw(smartmatch lexical_topic);
+my $DIST = basename $0, '.pl';
+
sub humanize; # convert numbers to human readable format
sub deletedir; # safely delete directories
sub confirm; # ask for user confirmation (HTML)
@@ -64,9 +67,13 @@
my $rxVIEW = qr/[a-z\d]{6}-[a-z\d]+/i; # date-userhash
my $rxFILE = qr/[a-z\d]{6}-[a-z\d]+-[dme]/i; # date-filehash-removalmode
-my $TT_CONFIG =
- { INCLUDE_PATH =>
- [map { catfile($RealBin, $_) } qw(var templates.override templates)] };
+my %TT_CONFIG = (
+ INCLUDE_PATH =>
+ [ (map { catfile($Bin, $_) } qw(templates templates.default templates.var) ),
+ #(map { catfile(dist_dir($DIST), $_) } qw(var templates.override templates)),
+ (map { catfile($RealBin, $_) } qw(templates.var templates)),
+ ]
+);
umask 077;
@@ -88,7 +95,7 @@
# for all R/W operations
-d $VAR
or mkdir $VAR => 0777
- or die "Can't mkdir $VAR: $! (your admin should have created it)\n";
+ or die "Can't mkdir $VAR: $! (Your admin should have created it. (uid:$> gids:$)))\n";
-x -w $VAR
or die "Can't write to $VAR: $!\n";
@@ -169,7 +176,7 @@
# create the view
my %tt = (view => $view);
- my $tt = Template->new($TT_CONFIG)
+ my $tt = Template->new(\%TT_CONFIG)
or die $Template::ERROR;
# List the current content
@@ -215,7 +222,9 @@
}
}
- $tt->process('inventory.html', \%tt) or die $tt->error();
+ $tt->process('inventory.html', \%tt) or die sprintf "template: %s\nINCLUDE_PATH\n%s\n",
+ $tt->error(),
+ join "\n", @{$TT_CONFIG{INCLUDE_PATH}};
return 0;
}
@@ -247,7 +256,7 @@
mimetype => $mimetype
}
);
- my $tt = Template->new($TT_CONFIG)
+ my $tt = Template->new(\%TT_CONFIG)
or die $Template::ERROR;
$tt->process('confirm.html' => \%tt);
exit 0;
--- a/configs/apache.conf Tue Dec 29 21:40:48 2015 +0100
+++ b/configs/apache.conf Tue Dec 29 22:59:42 2015 +0100
@@ -6,11 +6,11 @@
# SentEnv may go into the <Directory>...</Directory>
SetEnv ONCE_VAR /var/lib/once/
# Action may go into <Location>...</Location>
-Action once-upload-handler /once-handler/once.pl virtual
+Action once-handler /once-handler/once.pl virtual
# Order of location blocks matters!
<Location "/once">
- SetHandler once-upload-handler
+ SetHandler once-handler
</Location>
#<Location "/once/d">
--- a/templates.override/README Tue Dec 29 21:40:48 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-Put templates here. The templates in this directory will override the
-templates from the ../templates directory.