« blib/lib/auto/share/dist/Amon2/flavor/Minimum/t/Util.pm
↑ Summary
blib/lib/Amon2/Setup/Flavor/Basic.pm »
| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Amon2::Setup::Flavor; | ||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Text::Xslate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Path (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Amon2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Plack::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Amon2::Trigger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use mro; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use File::ShareDir (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Module::CPANfile 0.9020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub assets { | ||||||||||||||||||||||||||
|
Subroutine
assets: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | my @assets = qw( | |||||||||||||||||||||||||||
| 22 | XSRFTokenJS | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | 1 | @assets; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | sub infof { | ||||||||||||||||||||||||||
|
Subroutine
infof: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 3 | my $caller = do { | |||||||||||||||||||||||||||
| 29 | 3 | my $x; | |||||||||||||||||||||||||||
| 30 | 3 | for (1..10) { | |||||||||||||||||||||||||||
| 31 | 6 | $x = caller($_); | |||||||||||||||||||||||||||
| 32 | 6 | ▶ | last if $x ne __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 3 | $x; | |||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | 3 | $caller =~ s/^Amon2::Setup:://; | |||||||||||||||||||||||||||
| 37 | 3 | print "[$caller] "; | |||||||||||||||||||||||||||
| 38 | 3 | ▶ | @_==1 ? print(@_) : printf(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 3 | print "\n"; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | my %args = @_ ==1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | $args{amon2_version} = $Amon2::VERSION; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | for (qw/module/) { | |||||||||||||||||||||||||||
| 49 | 1 | ▶ | die "Missing mandatory parameter $_" unless exists $args{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 1 | $args{module} =~ s!-!::!g; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # $module = "Foo::Bar" | ||||||||||||||||||||||||||||
| 54 | # $dist = "Foo-Bar" | ||||||||||||||||||||||||||||
| 55 | # $path = "Foo/Bar" | ||||||||||||||||||||||||||||
| 56 | 1 | my @pkg = split /::/, $args{module}; | |||||||||||||||||||||||||||
| 57 | 1 | $args{dist} = join "-", @pkg; | |||||||||||||||||||||||||||
| 58 | 1 | $args{path} = join "/", @pkg; | |||||||||||||||||||||||||||
| 59 | 1 | my $self = bless { %args }, $class; | |||||||||||||||||||||||||||
| 60 | 1 | $self->{xslate} = $self->_build_xslate(); | |||||||||||||||||||||||||||
| 61 | 1 | $self->load_assets(); | |||||||||||||||||||||||||||
| 62 | 1 | $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub _build_xslate { | ||||||||||||||||||||||||||
|
Subroutine
_build_xslate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | my $xslate = Text::Xslate->new( | |||||||||||||||||||||||||||
| 69 | syntax => 'Kolon', | ||||||||||||||||||||||||||||
| 70 | type => 'text', | ||||||||||||||||||||||||||||
| 71 | tag_start => '<%', | ||||||||||||||||||||||||||||
| 72 | tag_end => '%>', | ||||||||||||||||||||||||||||
| 73 | line_start => '%%', | ||||||||||||||||||||||||||||
| 74 | path => [ File::Spec->catdir(File::ShareDir::dist_dir('Amon2'), 'flavor') ], | ||||||||||||||||||||||||||||
| 75 | module => [ | ||||||||||||||||||||||||||||
| 76 | 'Amon2::Util' => ['random_string'], | ||||||||||||||||||||||||||||
| 77 | ], | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 1 | $xslate; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub run { die "This is abstract base method" } | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub mkpath { | ||||||||||||||||||||||||||
|
Subroutine
mkpath: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | Carp::croak("path should not be ref") if ref $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | infof("mkpath: $path"); | |||||||||||||||||||||||||||
| 88 | 0 | File::Path::mkpath($path); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub render_string { | ||||||||||||||||||||||||||
|
Subroutine
render_string: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 0 | my $template = shift; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | my %args = @_==1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | return $self->{xslate}->render_string($template, {%$self, %args}); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub render_file { | ||||||||||||||||||||||||||
|
Subroutine
render_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 0 | my ($self, $dstname, $filename, $params) = @_; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | Carp::croak("filename should not be reference") if ref $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $dstname =~ s/<<([^>]+)>>/$self->{lc($1)} or die "$1 is not defined. But you want to use $1 in filename."/ge; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$self{lc $1} || die("$1 is not defined. But you want to use $1 in filename.")
MC/DC0%0/1
$$self{lc $1} || die("$1 is not defined. But you want to use $1 in filename.")
$$self{lc $1}
Truth table0%0/2
A
A= $$self{lc $1}
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $content = $self->{xslate}->render($filename, {%$self, $params ? %$params : () }); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $self->write_file_raw($dstname, $content); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub write_file { | ||||||||||||||||||||||||||
|
Subroutine
write_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $filename, $template) = (shift, shift, shift); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | Carp::croak("filename should not be reference") if ref $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $filename =~ s/<<([^>]+)>>/$self->{lc($1)} or die "$1 is not defined. But you want to use $1 in filename."/ge; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$self{lc $1} || die("$1 is not defined. But you want to use $1 in filename.")
MC/DC0%0/1
$$self{lc $1} || die("$1 is not defined. But you want to use $1 in filename.")
$$self{lc $1}
Truth table0%0/2
A
A= $$self{lc $1}
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my $content = $self->render_string($template, @_); | |||||||||||||||||||||||||||
| 114 | 0 | $self->write_file_raw($filename, $content); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | sub write_file_raw { | ||||||||||||||||||||||||||
|
Subroutine
write_file_raw: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 1 | my ($self, $filename, $content, $input_mode) = @_; | |||||||||||||||||||||||||||
| 119 | 1 | ▶ | Carp::croak("filename should not be reference") if ref $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | $input_mode ||= '>:encoding(utf-8)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$input_mode ||= ">:encoding(utf-8)"
MC/DC0%0/1
$input_mode ||= ">:encoding(utf-8)"
$input_mode
Truth table50%1/2
A
A= $input_mode
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | infof("writing $filename"); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | my $dirname = dirname($filename); | |||||||||||||||||||||||||||
| 125 | 1 | ▶ | File::Path::mkpath($dirname) if $dirname; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | ▶ | open my $ofh, $input_mode, $filename or die "Cannot open file: $filename: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 1 | print {$ofh} $content; | |||||||||||||||||||||||||||
| 129 | 1 | close $ofh; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub load_assets { | ||||||||||||||||||||||||||
|
Subroutine
load_assets: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 134 | 1 | for my $asset ($self->assets) { | |||||||||||||||||||||||||||
| 135 | 1 | $self->load_asset($asset); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | ▶ | sub load_asset { | ||||||||||||||||||||||||||
|
Subroutine
load_asset: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 2 | my ($self, $asset) = @_; | |||||||||||||||||||||||||||
| 141 | 2 | infof("Loading asset: $asset"); | |||||||||||||||||||||||||||
| 142 | 2 | my $klass = Plack::Util::load_class($asset, 'Amon2::Setup::Asset'); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | ▶ | my $require_newline = $self->{tags} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 2 | $self->{tags} .= $klass->tags; | |||||||||||||||||||||||||||
| 146 | 2 | ▶ | $self->{tags} .= "\n" if $require_newline && $self->{tags} !~ /\n\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$require_newline and not $self->{"tags"} =~ /\n\z/
MC/DC0%0/2
$require_newline and not $self->{"tags"} =~ /\n\z/
$require_newline
not $self->{"tags"} =~ /\n\z/
Truth table66%2/3
A and not(B)
A= $require_newlineB= not $self->{"tags"} =~ /\n\z/
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # $klass->run($self); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub write_asset { | ||||||||||||||||||||||||||
|
Subroutine
write_asset: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 1 | my ($self, $asset, $base) = @_; | |||||||||||||||||||||||||||
| 153 | 1 | ▶ | $asset || die "Missing asset name"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 1 | ▶ | $base ||= 'static/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$base ||= "static/"
MC/DC0%0/1
$base ||= "static/"
$base
Truth table50%1/2
A
A= $base
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | my $klass = Plack::Util::load_class($asset, 'Amon2::Setup::Asset'); | |||||||||||||||||||||||||||
| 157 | 1 | my $files = $klass->files; | |||||||||||||||||||||||||||
| 158 | 1 | ▶ | while (my ($fname, $content) = each %$files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | ▶ | my $layer = $fname =~ /\.js\z/ ? '>:encoding(utf-8)' : '>:raw'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 1 | $self->write_file_raw("$base/$fname", $content, $layer); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub write_assets { | ||||||||||||||||||||||||||
|
Subroutine
write_assets: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 165 | 0 | my ($self, $dst) = @_; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | for my $asset ($self->assets) { | |||||||||||||||||||||||||||
| 168 | 0 | $self->write_asset($asset, $dst); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub create_cpanfile { | ||||||||||||||||||||||||||
|
Subroutine
create_cpanfile: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 0 | my ($self, $runtime_deps) = @_; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | $runtime_deps ||= +{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$runtime_deps ||= {}
MC/DC0%0/1
$runtime_deps ||= {}
$runtime_deps
Truth table0%0/2
A
A= $runtime_deps
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | my $cpanfile = Module::CPANfile->from_prereqs( | |||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||
| 178 | runtime => { | ||||||||||||||||||||||||||||
| 179 | requires => { | ||||||||||||||||||||||||||||
| 180 | 'perl' => '5.010_001', | ||||||||||||||||||||||||||||
| 181 | 'Amon2' => $Amon2::VERSION, | ||||||||||||||||||||||||||||
| 182 | 'Text::Xslate' => '2.0009', | ||||||||||||||||||||||||||||
| 183 | 'Starlet' => '0.20', | ||||||||||||||||||||||||||||
| 184 | 'Module::Functions' => 2, | ||||||||||||||||||||||||||||
| 185 | %$runtime_deps, | ||||||||||||||||||||||||||||
| 186 | }, | ||||||||||||||||||||||||||||
| 187 | }, | ||||||||||||||||||||||||||||
| 188 | configure => { | ||||||||||||||||||||||||||||
| 189 | requires => { | ||||||||||||||||||||||||||||
| 190 | 'Module::Build' => '0.38', | ||||||||||||||||||||||||||||
| 191 | 'Module::CPANfile' => '0.9010', | ||||||||||||||||||||||||||||
| 192 | }, | ||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||
| 194 | test => { | ||||||||||||||||||||||||||||
| 195 | requires => { | ||||||||||||||||||||||||||||
| 196 | 'Test::More' => '0.98', | ||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||
| 198 | }, | ||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||
| 201 | 0 | $self->write_file('cpanfile', $cpanfile->to_string()); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 3 | 1; | |||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||