Initial release
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 19 Nov 2013 21:07:30 +0000 (23:07 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 19 Nov 2013 21:07:30 +0000 (23:07 +0200)
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/Gruntmaster/Handlers.pm [new file with mode: 0644]
t/Gruntmaster-Handlers.t [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..b08aff9
--- /dev/null
+++ b/Changes
@@ -0,0 +1,6 @@
+Revision history for Perl extension Gruntmaster::Handlers.
+
+0.001  Tue Nov  5 10:35:09 2013
+       - original version; created by h2xs 1.23 with options
+               -AX -b 5.14.0 -v 0.001 --skip-exporter Gruntmaster::Handlers
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..f768cf5
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,6 @@
+Changes
+Makefile.PL
+MANIFEST
+README
+t/Gruntmaster-Handlers.t
+lib/Gruntmaster/Handlers.pm
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..a74c781
--- /dev/null
@@ -0,0 +1,12 @@
+use 5.014000;
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+    NAME              => 'Gruntmaster::Handlers',
+    VERSION_FROM      => 'lib/Gruntmaster/Handlers.pm', # finds $VERSION
+    PREREQ_PM         => {}, # e.g., Module::Name => 1.1
+    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
+      (ABSTRACT_FROM  => 'lib/Gruntmaster/Handlers.pm', # retrieve abstract from module
+       AUTHOR         => 'Marius Gavrilescu <marius@>') : ()),
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..9378150
--- /dev/null
+++ b/README
@@ -0,0 +1,40 @@
+Gruntmaster-Handlers version 0.001
+==================================
+
+The README is used to introduce the module and provide instructions on
+how to install the module, any machine dependencies it may have (for
+example C compilers and installed libraries) and any other information
+that should be provided before the module is installed.
+
+A README file is required for CPAN modules since CPAN extracts the
+README file from a module distribution so that people browsing the
+archive can use it get an idea of the modules uses. It is usually a
+good idea to provide version information here so that people can
+decide whether fixes for the module are worth downloading.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+  blah blah blah
+
+COPYRIGHT AND LICENCE
+
+Put the correct copyright and licence information here.
+
+Copyright (C) 2013 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
+
+
diff --git a/lib/Gruntmaster/Handlers.pm b/lib/Gruntmaster/Handlers.pm
new file mode 100644 (file)
index 0000000..cb2393f
--- /dev/null
@@ -0,0 +1,123 @@
+package Gruntmaster::Handlers;
+
+use 5.014000;
+use strict;
+use warnings;
+our $VERSION = '0.001';
+
+use constant FORMAT_EXTENSION => {
+  CPP => 'cpp',
+};
+
+use Apache2::Access;
+use Apache2::AuthzCaps qw/hascaps/;
+use Apache2::RequestRec;
+use Apache2::RequestIO;
+use Apache2::Request;
+use Apache2::Const qw/OK DECLINED/;
+use Apache2::Log;
+use Apache2::Upload;
+
+use Cwd qw/cwd/;
+use File::Basename qw/fileparse/;
+use File::Temp qw/tempdir/;
+use File::Copy qw/move/;
+use YAML::Any qw/LoadFile DumpFile/;
+
+sub submit{
+  my $r = shift;
+  chdir $r->dir_config('root');
+  my $req = Apache2::Request->new($r);
+  my ($problem, $format) = ($req->param('problem'), $req->param('prog_format'));
+  my $ext = FORMAT_EXTENSION->{$format};
+  my $prog = $req->upload('prog');
+
+  my $dir = tempdir;
+  $prog->link("$dir/prog.$ext");
+  DumpFile "$dir/meta.yml", {
+       files => {
+         prog => {
+               format => $format,
+               name => 'prog.cpp',
+         }
+       },
+       problem => $problem,
+       user => $r->user,
+  };
+
+  my $jobname = int rand 1_000_000_000;
+  $jobname = int rand 1_000_000_000 while -d "jobs/$jobname";
+  move $dir, "jobs/$jobname" or die $!;
+
+  $r->print("Job submitted");
+  OK
+}
+
+sub private{
+  my $r = shift;
+  my $dir = (fileparse $r->uri)[1];
+  my $user = $r->user;
+  chdir $r->dir_config('root') . $dir;
+
+  for my $requirement (map { $_->{requirement} } @{$r->requires}) {
+       my ($command, @args) = split ' ', $requirement;
+
+       given ($command){
+         when('admin-if-private'){
+               my $meta = LoadFile 'meta.yml';
+               return OK if !$meta->{private} || ($r->user && hascaps $r->user, 'gmadm')
+         }
+
+       }
+  }
+
+  DECLINED
+}
+
+1;
+__END__
+# Below is stub documentation for your module. You'd better edit it!
+
+=head1 NAME
+
+Gruntmaster::Handlers - Perl extension for blah blah blah
+
+=head1 SYNOPSIS
+
+  use Gruntmaster::Handlers;
+  blah blah blah
+
+=head1 DESCRIPTION
+
+Stub documentation for Gruntmaster::Handlers, created by h2xs. It looks like the
+author of the extension was negligent enough to leave the stub
+unedited.
+
+Blah blah blah.
+
+
+=head1 SEE ALSO
+
+Mention other useful documentation such as the documentation of
+related modules or operating system documentation (such as man pages
+in UNIX), or any relevant external documentation such as RFCs or
+standards.
+
+If you have a mailing list set up for your module, mention it here.
+
+If you have a web site set up for your module, mention it here.
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@E<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2013 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
diff --git a/t/Gruntmaster-Handlers.t b/t/Gruntmaster-Handlers.t
new file mode 100644 (file)
index 0000000..deefe08
--- /dev/null
@@ -0,0 +1,18 @@
+# Before 'make install' is performed this script should be runnable with
+# 'make test'. After 'make install' it should work as 'perl Gruntmaster-Handlers.t'
+
+#########################
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+BEGIN { use_ok('Gruntmaster::Handlers') };
+
+#########################
+
+# Insert your test code below, the Test::More module is use()ed here so read
+# its man page ( perldoc Test::More ) for help writing this test script.
+
This page took 0.015891 seconds and 4 git commands to generate.