« blib/lib/Dist/Zilla/Plugin/GatherDir/Template.pm
↑ Summary
blib/lib/Dist/Zilla/Plugin/Encoding.pm »
| 1 | package Dist::Zilla::Util 6.040; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: random snippets of code that Dist::Zilla wants | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 55 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 55 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 55 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | Dist::Zilla::Util::PEA; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 55 | @Dist::Zilla::Util::PEA::ISA = ('Pod::Simple'); | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 14 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 14 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 14 | require Pod::Simple; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 14 | my $parser = $class->new(@args); | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 131 | ▶ | $parser->code_handler(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 131 | my ($line, $line_number, $parser) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 131 | ▶ | return if $parser->{abstract}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 43 | ▶ | return $parser->{abstract} = $1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | if $line =~ /^\s*#+\s*ABSTRACT:[ \t]*(\S.*)$/m; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 36 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | return $parser; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 61 | ▶ | sub _handle_element_start { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_start: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 61 | my ($parser, $ele_name, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 61 | ▶ | if ($ele_name eq 'head1') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 19 | $parser->{buffer} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | elsif ($ele_name eq 'Para') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 17 | $parser->{buffer} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | elsif ($ele_name eq 'C') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | $parser->{in_C} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 61 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 61 | ▶ | sub _handle_element_end { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_end: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 61 | my ($parser, $ele_name, $attr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 61 | ▶ | return if $parser->{abstract}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | if ($ele_name eq 'head1') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | $parser->{in_section} = $parser->{buffer}; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ▶ | elsif ($ele_name eq 'Para' && $parser->{in_section} eq 'NAME' ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ele_name eq "Para" and $parser->{"in_section"} eq "NAME"
MC/DC50%1/2
$ele_name eq "Para" and $parser->{"in_section"} eq "NAME"
$ele_name eq "Para"
$parser->{"in_section"} eq "NAME"
Truth table66%2/3
A and B
A= $ele_name eq "Para"B= $parser->{"in_section"} eq "NAME"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | if ($parser->{buffer} =~ /^(?:\S+\s+)+?-+\s+(.+)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | $parser->{abstract} = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | elsif ($ele_name eq 'C') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | delete $parser->{in_C}; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 49 | ▶ | sub _handle_text { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 49 | my ($parser, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # The C<...> tags are expected to be preserved. MetaCPAN renders them. | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 49 | ▶ | if ($parser->{in_C}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 9 | $parser->{buffer} .= "C<$text>"; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 40 | $parser->{buffer} .= $text; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 49 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | #pod =method abstract_from_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #pod This method, I<which is likely to change or go away>, tries to guess the | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | #pod abstract of a given file, assuming that it's Perl code. It looks for a POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | #pod C<=head1> section called "NAME" or a comment beginning with C<ABSTRACT:>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 55 | ▶ | sub abstract_from_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abstract_from_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | my $e = Dist::Zilla::Util::PEA->_new; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | $e->parse_string_document($file->content); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | return $e->{abstract}; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | #pod =method expand_config_package_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | #pod my $pkg_name = Dist::Zilla::Util->expand_config_package_name($string); | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | #pod This method, I<which is likely to change or go away>, rewrites the given string | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | #pod into a package name. | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | #pod Prefixes are rewritten as follows: | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | #pod =for :list | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | #pod * C<=> becomes nothing | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | #pod * C<@> becomes C<Dist::Zilla::PluginBundle::> | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | #pod * C<%> becomes C<Dist::Zilla::Stash::> | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | #pod * otherwise, C<Dist::Zilla::Plugin::> is prepended | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | #pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | #pod =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 55 | ▶ | use String::RewritePrefix 0.006 rewrite => { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | -as => '_expand_config_package_name', | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | prefixes => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | '=' => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | '@' => 'Dist::Zilla::PluginBundle::', | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | '%' => 'Dist::Zilla::Stash::', | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | '' => 'Dist::Zilla::Plugin::', | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 708 | ▶ | sub expand_config_package_name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_config_package_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 708 | shift; goto &_expand_config_package_name | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub homedir { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
homedir: not called CC=4 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $^O eq 'MSWin32' && "$]" < 5.016 ? $ENV{HOME} || $ENV{USERPROFILE} : (glob('~'))[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.5
Branch: 1 branch
Condition0%0/6
$^O eq "MSWin32" and "$]" < "5.016"
$ENV{"HOME"} or $ENV{"USERPROFILE"}
MC/DC0%0/2
$^O eq "MSWin32" and "$]" < "5.016"
$^O eq "MSWin32"
"$]" < "5.016"
MC/DC0%0/2
$ENV{"HOME"} or $ENV{"USERPROFILE"}
$ENV{"HOME"}
$ENV{"USERPROFILE"}
Truth table0%0/3
A and B
A= $^O eq "MSWin32"B= "$]" < "5.016"
Truth table0%0/3
A or B
A= $ENV{"HOME"}B= $ENV{"USERPROFILE"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | sub _global_config_root { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_global_config_root: called CC=3 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | require Dist::Zilla::Path; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return Dist::Zilla::Path::path($ENV{DZIL_GLOBAL_CONFIG_ROOT}) if $ENV{DZIL_GLOBAL_CONFIG_ROOT}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $homedir = homedir(); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | Carp::croak("couldn't determine home directory") if not $homedir; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return Dist::Zilla::Path::path($homedir)->child('.dzil'); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | sub _assert_loaded_class_version_ok { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_loaded_class_version_ok: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | my ($self, $pkg, $version) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | require CPAN::Meta::Requirements; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my $req = CPAN::Meta::Requirements->from_string_hash({ | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | $pkg => $version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | my $have_version = $pkg->VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | ▶ | unless ($req->accepts_module($pkg => $have_version)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | die( sprintf | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$have_version // "undef"
MC/DC0%0/1
$have_version // "undef"
$have_version
Truth table50%1/2
A
A= $have_version
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | "%s version (%s) does not match required version: %s\n", | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | $pkg, | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $have_version // 'undef', | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $version, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 55 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||