Dist/Zilla/Plugin/FFI/Mint.pm

filter: Statementstmt 100% 76 / 76 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 3 totaltotal 95.8% 93 / 97 CC 2 SCAR 1.1
CC
2
Cov
99%
munge_files
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« auto/share/module/Dist-Zilla-MintingProfile-FFI/default/Module.pm ↑ Summary Dist/Zilla/MintingProfile/FFI.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 package Dist::Zilla::Plugin::FFI::Mint 0.03 {
6  
7 2 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 with 'Dist::Zilla::Role::FileMunger', 'Dist::Zilla::Role::FileGatherer', 'Dist::Zilla::Role::ModuleMaker';
9 2 ▶ use experimental qw( signatures postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶ use Dist::Zilla::File::InMemory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: Generate module and modify dist.ini for use with FFI
14  
15 has lib_name => (
16 is => 'ro',
17 isa => 'Str',
18 lazy => 1,
19 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 $self->zilla->chrome->prompt_str("Library name (for libfoo.so or foo.dll enter 'foo')");
21 },
22 2 );
23  
24 has alien_name => (
25 is => 'ro',
26 isa => 'Str',
27 lazy => 1,
28 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 1 $self->zilla->chrome->prompt_str("Fallback Alien name");
30 },
31 2 );
32  
33 2 has module_package => (
34 is => 'rw',
35 isa => 'Str',
36 init_arg => undef,
37 );
38  
39 2 has module_filename => (
40 is => 'rw',
41 isa => 'Str',
42 init_arg => undef,
43 );
44  
45 has lib_package => (
46 is => 'ro',
47 isa => 'Str',
48 init_arg => undef,
49 lazy => 1,
50 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 $self->module_package . "::Lib";
52 },
53 2 );
54  
55 has lib_filename => (
56 is => 'ro',
57 isa => 'Str',
58 init_arg => undef,
59 lazy => 1,
60 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 1 $self->module_filename =~ s/\.pm$/\/Lib.pm/r;
62 },
63 2 );
64  
65 has test_filename => (
66 is => 'ro',
67 isa => 'Str',
68 init_arg => undef,
69 lazy => 1,
70 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 1 't/' . lc($self->module_package =~ s/::/_/gr) . ".t";
72 },
73 2 );
74  
75 1 ▶ sub munge_files ($self)
Subroutine munge_files: called CC=2 SCAR=6.9
Pod undocumented
76 {
77 1 my($dist_ini) = grep { $_->name eq 'dist.ini' } @{ $self->zilla->files };
78 1 ▶ $self->log_fatal("unable to find dist.ini") unless defined $dist_ini;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist_ini 0 1 1
79  
80 1 $self->log("Munge: @{[ $dist_ini->name ]}");
81  
82 1 my $code = $dist_ini->code;
83  
84 # this is hilariously stupid but this is what we are doing.
85 1 ▶ $dist_ini->code(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 1 my $content = $code->();
87 1 $content =~ s/##LIB_FILENAME##/$self->lib_filename/eg;
88 1 $content =~ s/##LIB_MODULENAME##/$self->lib_package/eg;
89 1 $content =~ s/##ALIEN_NAME##/$self->alien_name/eg;
90 1 $content;
91 1 });
92 }
93  
94 1 ▶ sub gather_files ($self)
Subroutine gather_files: called CC=1 SCAR=0.0
Pod undocumented
95 {
96 1 $self->log("Generate: @{[ $self->lib_filename ]}");
97 1 $self->add_file(
98 Dist::Zilla::File::InMemory->new({
99 name => $self->lib_filename,
100 content => <<"END1",
101 1 package @{[ $self->lib_package ]};
102  
103 use strict;
104 use warnings;
105 use FFI::CheckLib 0.28 qw( find_lib );
106  
107 sub lib {
108 1 find_lib lib => '@{[ $self->lib_name ]}', alien => '@{[ $self->alien_name ]}';
109 }
110  
111 1;
112  
113 =head1 NAME
114  
115 1 @{[ $self->lib_package ]} - Private class for @{[ $self->module_package ]}
116  
117 =head1 SYNOPSIS
118  
119 1 perldoc @{[ $self->module_package ]}
120  
121 =head1 DESCRIPTION
122  
123 This class is private.
124  
125 =head1 SEE ALSO
126  
127 =over 4
128  
129 1 =item @{[ $self->module_package ]}
130  
131 =back
132  
133 =cut
134 END1
135 })
136 );
137  
138 1 $self->log("Generate: @{[ $self->test_filename ]}");
139 1 $self->add_file(
140 Dist::Zilla::File::InMemory->new({
141 name => $self->test_filename,
142 content => <<"END2",
143 use Test2::V0;
144 1 use @{[ $self->module_package ]};
145  
146 ok 1;
147  
148 done_testing;
149 END2
150 }),
151 );
152 }
153  
154 1 ▶ sub make_module ($self, $arg)
Subroutine make_module: called CC=1 SCAR=0.0
Pod undocumented
155 {
156 1 $self->module_package($arg->{name});
157 1 $self->module_filename("lib/" . ($arg->{name} =~ s/::/\//gr) . ".pm");
158 1 $self->log("Creating main module: @{[ $self->module_filename ]}");
159  
160 1 my $file = Dist::Zilla::File::InMemory->new({
161 name => $self->module_filename,
162 content => <<"END3",
163 1 package @{[ $self->module_package ]};
164  
165 use strict;
166 use warnings;
167 use FFI::Platypus 1.00;
168 1 use @{[ $self->module_package ]}::Lib;
169  
170 my \$ffi = FFI::Platypus->new(
171 api => 1,
172 1 lib => [@{[ $self->module_package ]}::Lib->lib],
173 );
174  
175 #\$ffi->attach( ... );
176  
177 1;
178  
179 =head1 NAME
180  
181 1 @{[ $self->module_package ]} - Bindings for ...
182  
183 =head1 SYNOPSIS
184  
185 ...
186  
187 =head1 DESCRIPTION
188  
189 ...
190  
191 =cut
192 END3
193 });
194 1 $self->add_file($file);
195 }
196  
197 2 __PACKAGE__->meta->make_immutable;
198 }
199  
200 2 1;
201  
202 __END__
« auto/share/module/Dist-Zilla-MintingProfile-FFI/default/Module.pm ↑ Summary Dist/Zilla/MintingProfile/FFI.pm »