| 1 | package Boxer::File::WithSkeleton; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Role::Commons -all; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use namespace::autoclean 0.16; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Template::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use MooX::StrictConstructor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Types::Standard qw(Maybe); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Types::TypeTiny qw(HashLike); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Types::Path::Tiny qw(Dir File Path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Boxer::Types qw(SkelDir Basename); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | no warnings "experimental::signatures"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | Version v1.4.3 | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | our $VERSION = "v1.4.3"; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # permit callers to sloppily pass undefined values | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | sub BUILDARGS ( $class, %args ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | delete @args{ grep !defined( $args{$_} ), keys %args }; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | return {%args}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | has basename => ( | |||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => Basename, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | has file => ( | ||||||||||||||||||||||||||||||||||||||||||
| 49 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | isa => Basename, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | default => sub ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | if ( $self->basename ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | return $self->basename; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | elsif ( $self->skeleton_suffix ) { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return $self->skeleton_path->basename( $self->skeleton_suffix ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | has file_path => ( | ||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => Path, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | ▶ | default => sub ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if ( $self->file_dir and $self->file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->file_dir and $self->file
MC/DC0%0/2
$self->file_dir and $self->file
$self->file_dir
$self->file
Truth table33%1/3
A and B
A= $self->file_dirB= $self->file
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | return $self->file_dir->child( $self->file ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | has file_dir => ( | ||||||||||||||||||||||||||||||||||||||||||
| 74 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | isa => Dir, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | default => sub { path('.') }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | has skeleton => ( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | isa => Basename, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | default => sub ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | ▶ | if ( $self->basename | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->basename and $self->skeleton_dir and $self->skeleton_suffix
$self->basename and $self->skeleton_dir
MC/DC0%0/3
$self->basename and $self->skeleton_dir and $self->skeleton_suffix
$self->basename
$self->skeleton_dir
$self->skeleton_suffix
Truth table25%1/4
A and B and C
A= $self->basenameB= $self->skeleton_dirC= $self->skeleton_suffix
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | and $self->skeleton_dir | ||||||||||||||||||||||||||||||||||||||||||
| 85 | and $self->skeleton_suffix ) | ||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | return $self->skeleton_dir->child( | |||||||||||||||||||||||||||||||||||||||||
| 88 | $self->basename . $self->skeleton_suffix )->basename; | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | has skeleton_path => ( | ||||||||||||||||||||||||||||||||||||||||||
| 94 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | isa => File, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | default => sub ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if ( $self->skeleton_dir and $self->skeleton ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->skeleton_dir and $self->skeleton
MC/DC0%0/2
$self->skeleton_dir and $self->skeleton
$self->skeleton_dir
$self->skeleton
Truth table33%1/3
A and B
A= $self->skeleton_dirB= $self->skeleton
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | return $self->skeleton_dir->child( $self->skeleton ); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | has skeleton_dir => ( | ||||||||||||||||||||||||||||||||||||||||||
| 105 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 106 | isa => SkelDir, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | default => sub { path( dist_dir('Boxer'), 'skel' ) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | has skeleton_suffix => ( | |||||||||||||||||||||||||||||||||||||||||
| 111 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | isa => Basename, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | default => '.in', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | sub create ( $self, $vars ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | my $template = Template::Tiny->new( | |||||||||||||||||||||||||||||||||||||||||
| 119 | TRIM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | my $content = ''; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | $template->process( | |||||||||||||||||||||||||||||||||||||||||
| 124 | \$self->skeleton_path->slurp, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | $vars, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | \$content | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | $self->file_path->spew( $content . "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Jonas Smedegaard C<< <dr@jones.dk> >>. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | our $AUTHORITY = 'cpan:JONASS'; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | Copyright © 2013-2016 Jonas Smedegaard | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 144 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||||||||||||||||
| 149 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||||||||||||
| 150 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||