bye bye github
This commit is contained in:
62
lib/Dojo/Support.pm
Normal file
62
lib/Dojo/Support.pm
Normal file
@@ -0,0 +1,62 @@
|
||||
package Dojo::Support;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Exporter 'import';
|
||||
our @EXPORT = qw/ dmph merge_hash load_module /;
|
||||
use Mojo::Base 'Mojolicious';
|
||||
|
||||
use File::Basename;
|
||||
use Mojo::File 'path';
|
||||
use Path::Class;
|
||||
use Encode qw{ decode_utf8 };
|
||||
use Hash::Merge;
|
||||
use Dojo::Conf;
|
||||
|
||||
|
||||
|
||||
sub get_names{
|
||||
my $dir = shift;
|
||||
my @file_name;
|
||||
opendir(DIR, $dir) or die "error opening dir: $dir \n$!";
|
||||
while (my $file = readdir(DIR)) {
|
||||
next unless ( $file =~m/^[\w\d]/);
|
||||
next unless (-f "$dir/$file");
|
||||
push(@file_name,$file);
|
||||
}
|
||||
closedir(DIR);
|
||||
return sort @file_name;
|
||||
};
|
||||
|
||||
sub merge_hash{
|
||||
my ($v,$w)=@_;
|
||||
my $merger = Hash::Merge->new('LEFT_PRECEDENT');
|
||||
return $merger->merge( $v, $w );
|
||||
}
|
||||
|
||||
sub load_module{
|
||||
my $c=shift;
|
||||
my $dir=shift //"$c->{stash}{controller}/$c->{stash}{action}";
|
||||
my $lpath= Dojo::Conf::MOD."/$dir";
|
||||
my $h; $h->{js}=[]; $h->{css}=[]; #no me gusta!!!
|
||||
$h->{layout} = "default";
|
||||
my $q;
|
||||
my @s= get_names($lpath);
|
||||
foreach (@s) {
|
||||
push(@{$h->{$1}}, "/$dir/$_") if /.*\.(css|js)$/;
|
||||
push(@{$q->{$1}}, "/$dir/$_") if /.*\.(q|json|txt|md)$/;
|
||||
}
|
||||
return ($h,$q);
|
||||
};
|
||||
|
||||
|
||||
sub dmph{
|
||||
my $x = shift;
|
||||
my $y=" ";
|
||||
foreach (sort(keys %$x)) {
|
||||
$y= "$y $_ = $x->{$_} \n";
|
||||
}
|
||||
return $y;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user