| 1 | package Dist::Zilla::Plugin::Typemap; | ||||||||||||||
| 2 | 1 | $Dist::Zilla::Plugin::Typemap::VERSION = '0.006'; | |||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | with 'Dist::Zilla::Role::FileGatherer', 'Dist::Zilla::Role::PrereqSource'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | ▶ | use experimental 'signatures', 'postderef'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | use Dist::Zilla::File::InMemory; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use List::Util qw/first max/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use MooseX::Types::Moose qw/ArrayRef Bool Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use MooseX::Types::Perl qw/StrictVersionStr/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use ExtUtils::Typemaps; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 1 | ▶ | use Module::Runtime 'require_module'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 1 | ▶ | use Carp 'croak'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | ▶ | sub mvp_multivalue_args { | ||||||||||||
|
Subroutine
mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 18 | 0 | return qw/modules files/; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | sub mvp_aliases { | ||||||||||||
|
Subroutine
mvp_aliases: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 22 | return { | ||||||||||||||
| 23 | 0 | module => 'modules', | |||||||||||||
| 24 | file => 'files', | ||||||||||||||
| 25 | }; | ||||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | has modules => ( | ||||||||||||||
| 29 | isa => ArrayRef, | ||||||||||||||
| 30 | traits => ['Array'], | ||||||||||||||
| 31 | 0 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 32 | 1 | handles => { | |||||||||||||
| 33 | modules => 'elements', | ||||||||||||||
| 34 | }, | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | has files => ( | ||||||||||||||
| 38 | isa => ArrayRef, | ||||||||||||||
| 39 | traits => ['Array'], | ||||||||||||||
| 40 | 0 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 41 | 1 | handles => { | |||||||||||||
| 42 | files => 'elements', | ||||||||||||||
| 43 | }, | ||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | has minimum_pxs => ( | |||||||||||||
| 47 | is => 'ro', | ||||||||||||||
| 48 | isa => Str, | ||||||||||||||
| 49 | default => 'auto', | ||||||||||||||
| 50 | ); | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 1 | has filename => ( | |||||||||||||
| 53 | is => 'ro', | ||||||||||||||
| 54 | isa => Str, | ||||||||||||||
| 55 | default => 'typemap', | ||||||||||||||
| 56 | ); | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | sub gather_files($self) { | ||||||||||||
|
Subroutine
gather_files: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 59 | 0 | my ($file) = grep { $_->name eq $self->filename } $self->zilla->files->@*; | |||||||||||||
| 60 | 0 | ▶ | if (!$file) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 0 | $file = Dist::Zilla::File::InMemory->new( | |||||||||||||
| 62 | name => $self->filename, | ||||||||||||||
| 63 | content => '', | ||||||||||||||
| 64 | ); | ||||||||||||||
| 65 | 0 | $self->add_file($file); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | 0 | $self->munge_file($file); | |||||||||||||
| 68 | |||||||||||||||
| 69 | return | ||||||||||||||
| 70 | 0 | } | |||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | sub munge_file($self, $file) { | ||||||||||||
|
Subroutine
munge_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 73 | 0 | my $typemap = ExtUtils::Typemaps->new(string => $file->content); | |||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | for my $name ($self->modules) { | |||||||||||||
| 76 | 0 | my $module = $name =~ s/^\+/ExtUtils::Typemaps::/gr; | |||||||||||||
| 77 | 0 | require_module($module); | |||||||||||||
| 78 | 0 | $typemap->merge(typemap => $module->new); | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 0 | for my $filename ($self->files) { | |||||||||||||
| 82 | 0 | ▶ | my $file = first { $_->name eq $filename } $self->zilla->files->@* or croak "No such typemap file $filename"; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||
| 83 | 0 | $typemap->add_string(string => $file->content); | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | $file->content($typemap->as_string); | |||||||||||||
| 87 | |||||||||||||||
| 88 | 0 | return; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | ▶ | sub register_prereqs($self) { | ||||||||||||
|
Subroutine
register_prereqs: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 92 | 0 | my $version = $self->minimum_pxs; | |||||||||||||
| 93 | 0 | my @modules = map { s/^\+/ExtUtils::Typemaps::/gr } $self->modules; | |||||||||||||
| 94 | 0 | ▶ | if ($version eq 'auto') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 95 | 0 | my @versions = 0; | |||||||||||||
| 96 | 0 | for my $module (@modules) { | |||||||||||||
| 97 | 0 | require_module($module); | |||||||||||||
| 98 | 0 | ▶ | push @versions, $module->minimum_pxs if $module->can('minimum_pxs'); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | } | ||||||||||||||
| 100 | 0 | $version = max(@versions); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | elsif ($version eq 'author') { | ||||||||||||||
| 103 | 0 | require Module::Metadata; | |||||||||||||
| 104 | 0 | $version = Module::Metadata->new_from_module('ExtUtils::ParseXS')->version->stringify; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | 0 | ▶ | $self->zilla->register_prereqs({ phase => 'build' }, 'ExtUtils::ParseXS' => $version) if $version; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | for my $module (@modules) { | |||||||||||||
| 109 | 0 | $self->zilla->register_prereqs({ phase => 'develop' }, $module => 0); | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | |||||||||||||||
| 112 | 0 | return; | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | |||||||||||||||
| 115 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 116 | 1 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 117 | |||||||||||||||
| 118 | 1 | 1; | |||||||||||||
| 119 | |||||||||||||||
| 120 | # ABSTRACT: Manipulate the typemap file for XS distributions using dzil | ||||||||||||||
| 121 | |||||||||||||||
| 122 | __END__ | ||||||||||||||