Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 57e434e857
Fetching contributors…

Cannot retrieve contributors at this time

file 86 lines (73 sloc) 1.541 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
package Eplouribousse;
use autodie;
use Modern::Perl;
use File::Basename;
use File::Path qw< make_path >;
use Exporter qw< import >;
our @EXPORT = qw<
path_of dir_path ppn_dir rcr_dir gate
missing_in keys_multiv
OK serve
trim
is_file is_dir append_to
>;


sub is_file {
    my $file = shift;
    -f $file or do {
        map { -d or make_path $_ } dirname $file;
        open my $fh,'>', $file;
    };
    $file;
}

sub is_dir {
    my $dir = shift;
    make_path $dir;
    -d $dir or make_path $dir or die $!;
    $dir;
}


sub append_to {
    my $file = shift;
    is_file $file;
    open my $fh,'>>',$file or die $!;
    say $fh $_ for @_;
}

sub missing_in {
    my $in = shift;
    grep { not exists $$in{$_} } @_
}

sub keys_multiv {
    my $in = shift;
    grep { (!ref $$in{$_} ) || ( @{ $$in{$_} } > 1 ) } keys %$in;
}


sub path_of {
    my $base = shift;
    join '/'
    , $base
    , substr( $_[0], 0, 3 )
    , @_;
}
sub dir_path {
    my $path = path_of @_;
    make_path $path;
    $path;
}
sub ppn_dir { dir_path ppn => @_ }
sub rcr_dir { dir_path rcr => @_ }
sub gate {
    my ( $mode, $key, $file, $id ) = @_;
    my $dir = dir_path $key, $id;
    $mode =~ s/^P// and make_path $dir;
    open my $fh, $mode, "$dir/$file";
    $fh
}

sub trim { s{ ^\s+ | \s+$ }//g }
sub OK { 200 };
sub serve {
    state $header =
    [ qw<
Content-Script-Type text/javascript
Content-Style-Type text/css
Content-Type >, 'text/html; charset=UTF-8'];

    [ OK, $header , [@_] ]
}


1;
Something went wrong with that request. Please try again.