Amon2
view release on metacpan or search on metacpan
lib/Amon2/Setup/Flavor.pm view on Meta::CPAN
use strict;
use warnings;
use utf8;
package Amon2::Setup::Flavor;
use Text::Xslate;
use File::Spec;
use File::Basename;
use File::Path ();
use Amon2;
use Plack::Util ();
use Carp ();
use Amon2::Trigger;
use mro;
use File::ShareDir ();
use Module::CPANfile 0.9020;
sub assets {
my $self = shift;
my @assets = qw(
XSRFTokenJS
);
@assets;
}
sub infof {
my $caller = do {
my $x;
for (1..10) {
$x = caller($_);
last if $x ne __PACKAGE__;
}
$x;
};
$caller =~ s/^Amon2::Setup:://;
print "[$caller] ";
@_==1 ? print(@_) : printf(@_);
print "\n";
}
sub new {
my $class = shift;
my %args = @_ ==1 ? %{$_[0]} : @_;
$args{amon2_version} = $Amon2::VERSION;
for (qw/module/) {
die "Missing mandatory parameter $_" unless exists $args{$_};
}
$args{module} =~ s!-!::!g;
# $module = "Foo::Bar"
# $dist = "Foo-Bar"
# $path = "Foo/Bar"
my @pkg = split /::/, $args{module};
$args{dist} = join "-", @pkg;
$args{path} = join "/", @pkg;
my $self = bless { %args }, $class;
$self->{xslate} = $self->_build_xslate();
$self->load_assets();
$self;
}
sub _build_xslate {
my $self = shift;
my $xslate = Text::Xslate->new(
syntax => 'Kolon',
type => 'text',
tag_start => '<%',
tag_end => '%>',
line_start => '%%',
path => [ File::Spec->catdir(File::ShareDir::dist_dir('Amon2'), 'flavor') ],
module => [
'Amon2::Util' => ['random_string'],
],
);
$xslate;
}
sub run { die "This is abstract base method" }
sub mkpath {
my ($self, $path) = @_;
Carp::croak("path should not be ref") if ref $path;
infof("mkpath: $path");
File::Path::mkpath($path);
}
sub render_string {
( run in 1.619 second using v1.01-cache-2.11-cpan-5511b514fd6 )