File Coverage

blib/lib/Alien/Build/MB.pm
Criterion Covered Total %
statement 103 112 91.9
branch 14 20 70.0
condition 1 2 50.0
subroutine 12 14 85.7
pod 5 7 71.4
total 135 155 87.1


line stmt bran cond sub pod time code
1             package Alien::Build::MB;
2              
3 1     1   197503 use strict;
  1         8  
  1         24  
4 1     1   5 use warnings;
  1         2  
  1         19  
5 1     1   684 use Path::Tiny ();
  1         10181  
  1         25  
6 1     1   615 use Alien::Build;
  1         44122  
  1         38  
7 1     1   8 use base qw( Module::Build );
  1         2  
  1         466  
8              
9             # ABSTRACT: Alien::Build installer class for Module::Build
10             our $VERSION = '0.08'; # VERSION
11              
12              
13             sub new
14             {
15 4     4 1 27636 my($class, %args) = @_;
16              
17 4 50       55 if(! -f 'alienfile')
18             {
19 0         0 die "unable to find alienfile";
20             }
21             else
22             {
23 4         54 my $build = Alien::Build->load('alienfile', root => '_alien');
24 4         28187 $build->load_requires('configure');
25 4         278 $build->root;
26 4         1161 $build->checkpoint;
27             }
28              
29 4         5134 my $self = $class->SUPER::new(%args);
30              
31 4         51624 my $build = $self->alien_build(1);
32              
33 4         88 $self->_add_prereq( "${_}_requires", 'Module::Build' => '0.36' ) for qw( configure build );
34 4         267 $self->_add_prereq( "${_}_requires", 'Alien::Build::MB' => '0.01' ) for qw( configure build );
35 4         212 $self->add_to_cleanup("_alien");
36              
37 4         538 foreach my $hook_name (qw( test_ffi test_share test_system ))
38             {
39 12 100       147 if($build->meta->has_hook($hook_name))
40             {
41 2         45 $self->_add_prereq( "configure_requires", 'Alien::Build::MB' => '0.05');
42 2         394 last;
43             }
44             }
45              
46 4         37 my %config_requires = %{ $build->requires('configure') };
  4         29  
47 4         93 foreach my $module (keys %config_requires)
48             {
49 4         13 my $version = $config_requires{$module};
50 4         14 $self->_add_prereq( 'configure_requires', $module => $version );
51             }
52              
53 4 50       122 unless($build->install_type =~ /^(share|system)$/)
54             {
55 0         0 die "unknown install type: @{[ $build->install_type ]}";
  0         0  
56             }
57              
58 4         5958 my %build_requires = %{ $build->requires($build->install_type) };
  4         15  
59 4         141 foreach my $module (keys %build_requires)
60             {
61 2         5 my $version = $build_requires{$module};
62 2         15 $self->_add_prereq( 'build_requires', $module => $version );
63             }
64              
65 4 50       82 my $final_dest = $self->install_destination($build->meta_prop->{arch} ? 'arch' : 'lib');
66              
67 4         3535 my $prefix = Path::Tiny->new($final_dest)
68             ->child("auto/share/dist")
69             ->child($self->dist_name)
70             ->absolute;
71 4         539 my $stage = Path::Tiny->new("blib/lib/auto/share/dist")
72             ->child($self->dist_name)
73             ->absolute;
74              
75 4         438 $build->set_stage ($stage->stringify );
76 4         108 $build->set_prefix($prefix->stringify);
77 4         119 $build->runtime_prop->{perl_module_version} = $self->dist_version;
78              
79 4         88 $build->checkpoint;
80              
81 4 50       7912 if($self->alien_alienfile_meta)
82             {
83             $self->meta_merge->{x_alienfile} = {
84 4   50     21 generated_by => "@{[ __PACKAGE__ ]} version @{[ __PACKAGE__->VERSION || 'dev' ]}",
  4         124  
85             requires => {
86             map {
87 4         57 my %reqs = %{ $build->requires($_) };
  8         18  
  8         21  
88 8         220 $reqs{$_} = "$reqs{$_}" for keys %reqs;
89 8         75 $_ => \%reqs;
90             } qw( share system )
91             },
92             };
93             }
94              
95 4         162 $self;
96             }
97              
98              
99             __PACKAGE__->add_property( alien_alienfile_meta => 1 );
100              
101              
102             sub alien_build
103             {
104 19     19 1 14727 my($self, $noload) = @_;
105 19         198 my $build = Alien::Build->resume('alienfile', '_alien');
106 19         127288 $build->load_requires('configure');
107 19 100       1558 $build->load_requires($build->install_type) unless $noload;
108 19         459 $build;
109             }
110              
111             sub _alien_already_done ($)
112             {
113 11     11   94 my($name) = @_;
114 11         76 my $path = Path::Tiny->new("_alien/mb/$name");
115 11         371 return -f $path;
116             }
117              
118             sub _alien_touch ($)
119             {
120 8     8   42 my($name) = @_;
121 8         70 my $path = Path::Tiny->new("_alien/mb/$name");
122 8         278 $path->parent->mkpath;
123 8         1762 $path->touch;
124             }
125              
126              
127             sub ACTION_alien_download
128             {
129 5     5 1 9289 my($self) = @_;
130 5 100       17 return $self if _alien_already_done 'download';
131 4         82 my $build = $self->alien_build;
132 4         36 $build->download;
133 4         2755 $build->checkpoint;
134 4         7389 _alien_touch 'download';
135 4         845 $self;
136             }
137              
138              
139             sub ACTION_alien_build
140             {
141 6     6 1 12058 my($self) = @_;
142 6 100       27 return $self if _alien_already_done 'build';
143 4         140 $self->depends_on('alien_download');
144              
145 4         133 my $build = $self->alien_build;
146 4         100 $build->build;
147              
148 4 50       21459 if($build->meta_prop->{arch})
149             {
150 4         67 my $archdir = Path::Tiny->new("./blib/arch/auto/@{[ join '/', split /-/, $self->dist_name ]}");
  4         30  
151 4         264 $archdir->mkpath;
152 4         1580 my $archfile = $archdir->child($archdir->basename . ".txt");
153 4         255 $archfile->spew('Alien based distribution with architecture specific file in share');
154             }
155              
156             {
157 4         1548 my @parts = split /-/, $self->dist_name;
  4         21  
158 4         61 my $package = join '::', @parts;
159 4         22 my $install_files = Path::Tiny->new("./blib/lib")->child( @parts, 'Install', 'Files.pm' );
160 4         322 $install_files->parent->mkpath;
161 4         1228 $install_files->spew_utf8(
162             "package ${package}::Install::Files;\n",
163             "use strict;\n",
164             "use warnings;\n",
165             "require ${package};\n",
166             "sub Inline { shift; ${package}->Inline(\@_) }\n",
167             "1;\n",
168             "\n",
169             "=begin Pod::Coverage\n",
170             "\n",
171             " Inline\n",
172             "\n",
173             "=cut\n",
174             );
175             };
176              
177 4         3113 $build->checkpoint;
178              
179 4         9617 _alien_touch 'build';
180 4         787 $self;
181             }
182              
183              
184             sub ACTION_alien_test
185             {
186 2     2 1 4862 my($self) = @_;
187 2         20 $self->depends_on('alien_build');
188              
189 2         76 my $build = $self->alien_build;
190 2 50       23 if($build->can('test'))
191             {
192 2         23 $build->test;
193 1         1001 $build->checkpoint;
194             }
195 1         2381 $self;
196             }
197              
198             sub ACTION_test
199             {
200 0     0 0   my($self) = @_;
201 0           $self->depends_on('alien_test');
202 0           $self->SUPER::ACTION_test;
203             }
204              
205             sub ACTION_code
206             {
207 0     0 0   my($self) = @_;
208 0           $self->depends_on('alien_build');
209 0           $self->SUPER::ACTION_code;
210             }
211              
212             1;
213              
214             __END__