| 1 | 2 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Dist::Zilla::Plugin::INI::Baked; | ||||||||||
| 6 | |||||||||||
| 7 | 2 | our $VERSION = '0.002002'; | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Add a baked version of your configuration to tree automatically | ||||||||||
| 10 | |||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use Moose qw( with has around ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use MooX::Lsub qw( lsub ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | ▶ | use Dist::Zilla::File::FromCode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | use Dist::Zilla::Util::CurrentCmd 0.002000 qw( as_cmd ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use Path::Tiny qw( path ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Dist::Zilla::Util::ExpandINI 0.001001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 2 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 2 | ▶ | lsub 'filename' => sub { 'dist.ini.baked' }; | ||||||||
|
Subroutine
_build_filename: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | lsub 'source_filename' => sub { 'dist.ini' }; | ||||||||
|
Subroutine
_build_source_filename: not called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
| |||||||||||
| 45 | |||||||||||
| 46 | 2 | ▶ | lsub '_root' => sub { path( $_[0]->zilla->root ) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 2 | ▶ | lsub '_source_file' => sub { $_[0]->_root->child( $_[0]->source_filename ) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | around dump_config => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 50 | 0 | my ( $orig, $self, @args ) = @_; | |||||||||
| 51 | 0 | my $config = $self->$orig(@args); | |||||||||
| 52 | 0 | my $localconf = $config->{ +__PACKAGE__ } = {}; | |||||||||
| 53 | |||||||||||
| 54 | 0 | $localconf->{filename} = $self->filename; | |||||||||
| 55 | 0 | $localconf->{source_filename} = $self->source_filename; | |||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | unless __PACKAGE__ eq ref $self; | ||||||||||
| 59 | |||||||||||
| 60 | 0 | return $config; | |||||||||
| 61 | 2 | }; | |||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | sub _gen_preamble { | ||||||||
|
Subroutine
_gen_preamble: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 2 | my ($self) = @_; | |||||||||
| 65 | 2 | my $out = q[]; | |||||||||
| 66 | 2 | $out .= sprintf qq[; This file is generated from %s ( in the source repository ) by %s.\n], $self->filename, $self->meta->name; | |||||||||
| 67 | 2 | $out .= qq[; It exists for your convenience for development if you need it.\n]; | |||||||||
| 68 | 2 | $out .= sprintf qq[; You should edit %s in the source repository for any long term changes\n], $self->filename; | |||||||||
| 69 | 2 | return $out; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | sub _inflate_ini { | ||||||||
|
Subroutine
_inflate_ini: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 2 | my ($self) = @_; | |||||||||
| 74 | 2 | my $state = Dist::Zilla::Util::ExpandINI->new(); | |||||||||
| 75 | 2 | $state->_load_file( $self->_source_file ); | |||||||||
| 76 | 2 | $state->_expand(); | |||||||||
| 77 | 2 | return $state->_store_string; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 2 | ▶ | sub _gen_ini { | ||||||||
|
Subroutine
_gen_ini: called CC=1 SCAR=0.0
| |||||||||||
| 81 | 2 | my ($self) = @_; | |||||||||
| 82 | 2 | my $out = $self->_gen_preamble; | |||||||||
| 83 | 2 | ▶ | as_cmd( 'bakeini' => sub { $out .= $self->_inflate_ini } ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 2 | return $out; | |||||||||
| 85 | |||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | 2 | ▶ | sub gather_files { | ||||||||
|
Subroutine
gather_files: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 97 | 2 | my ($self) = @_; | |||||||||
| 98 | |||||||||||
| 99 | 2 | ▶ | if ( not -e $self->_source_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | return $self->log_fatal( [ 'Can\'t bake %s, it does not exist', $self->_source_file->stringify ] ); | |||||||||
| 101 | } | ||||||||||
| 102 | my $file = Dist::Zilla::File::FromCode->new( | ||||||||||
| 103 | { | ||||||||||
| 104 | name => $self->filename, | ||||||||||
| 105 | added_by => $self->meta->name, | ||||||||||
| 106 | code_return_type => 'text', | ||||||||||
| 107 | 2 | ▶ | code => sub { $self->_gen_ini }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 108 | }, | ||||||||||
| 109 | 2 | ); | |||||||||
| 110 | 2 | $self->add_file($file); | |||||||||
| 111 | 2 | return; | |||||||||
| 112 | } | ||||||||||
| 113 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 114 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 115 | |||||||||||
| 116 | 2 | 1; | |||||||||
| 117 | |||||||||||
| 118 | __END__ | ||||||||||