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 2     2   191531 use strict;
  2         9  
  2         76  
4 2     2   10 use warnings;
  2         4  
  2         40  
5 2     2   1237 use Path::Tiny ();
  2         18198  
  2         45  
6 2     2   1086 use Alien::Build;
  2         80439  
  2         72  
7 2     2   14 use base qw( Module::Build );
  2         3  
  2         934  
8              
9             # ABSTRACT: Alien::Build installer class for Module::Build
10             our $VERSION = '0.07'; # VERSION
11              
12              
13             sub new
14             {
15 4     4 1 27880 my($class, %args) = @_;
16              
17 4 50       53 if(! -f 'alienfile')
18             {
19 0         0 die "unable to find alienfile";
20             }
21             else
22             {
23 4         31 my $build = Alien::Build->load('alienfile', root => '_alien');
24 4         20388 $build->load_requires('configure');
25 4         252 $build->root;
26 4         950 $build->checkpoint;
27             }
28              
29 4         6396 my $self = $class->SUPER::new(%args);
30              
31 4         47340 my $build = $self->alien_build(1);
32              
33 4         104 $self->_add_prereq( "${_}_requires", 'Module::Build' => '0.36' ) for qw( configure build );
34 4         221 $self->_add_prereq( "${_}_requires", 'Alien::Build::MB' => '0.01' ) for qw( configure build );
35 4         219 $self->add_to_cleanup("_alien");
36              
37 4         503 foreach my $hook_name (qw( test_ffi test_share test_system ))
38             {
39 12 100       177 if($build->meta->has_hook($hook_name))
40             {
41 2         51 $self->_add_prereq( "configure_requires", 'Alien::Build::MB' => '0.05');
42 2         370 last;
43             }
44             }
45              
46 4         43 my %config_requires = %{ $build->requires('configure') };
  4         59  
47 4         93 foreach my $module (keys %config_requires)
48             {
49 4         11 my $version = $config_requires{$module};
50 4         19 $self->_add_prereq( 'configure_requires', $module => $version );
51             }
52              
53 4 50       99 unless($build->install_type =~ /^(share|system)$/)
54             {
55 0         0 die "unknown install type: @{[ $build->install_type ]}";
  0         0  
56             }
57              
58 4         5541 my %build_requires = %{ $build->requires($build->install_type) };
  4         21  
59 4         163 foreach my $module (keys %build_requires)
60             {
61 2         6 my $version = $build_requires{$module};
62 2         9 $self->_add_prereq( 'build_requires', $module => $version );
63             }
64              
65 4 50       70 my $final_dest = $self->install_destination($build->meta_prop->{arch} ? 'arch' : 'lib');
66              
67 4         3461 my $prefix = Path::Tiny->new($final_dest)
68             ->child("auto/share/dist")
69             ->child($self->dist_name)
70             ->absolute;
71 4         481 my $stage = Path::Tiny->new("blib/lib/auto/share/dist")
72             ->child($self->dist_name)
73             ->absolute;
74              
75 4         496 $build->set_stage ($stage->stringify );
76 4         92 $build->set_prefix($prefix->stringify);
77 4         143 $build->runtime_prop->{perl_module_version} = $self->dist_version;
78              
79 4         90 $build->checkpoint;
80              
81 4 50       41528 if($self->alien_alienfile_meta)
82             {
83             $self->meta_merge->{x_alienfile} = {
84 4   50     26 generated_by => "@{[ __PACKAGE__ ]} version @{[ __PACKAGE__->VERSION || 'dev' ]}",
  4         118  
85             requires => {
86             map {
87 4         133 my %reqs = %{ $build->requires($_) };
  8         14  
  8         25  
88 8         228 $reqs{$_} = "$reqs{$_}" for keys %reqs;
89 8         80 $_ => \%reqs;
90             } qw( share system )
91             },
92             };
93             }
94              
95 4         133 $self;
96             }
97              
98              
99             __PACKAGE__->add_property( alien_alienfile_meta => 1 );
100              
101              
102             sub alien_build
103             {
104 19     19 1 14117 my($self, $noload) = @_;
105 19         133 my $build = Alien::Build->resume('alienfile', '_alien');
106 19         107511 $build->load_requires('configure');
107 19 100       1271 $build->load_requires($build->install_type) unless $noload;
108 19         418 $build;
109             }
110              
111             sub _alien_already_done ($)
112             {
113 11     11   42 my($name) = @_;
114 11         60 my $path = Path::Tiny->new("_alien/mb/$name");
115 11         323 return -f $path;
116             }
117              
118             sub _alien_touch ($)
119             {
120 8     8   49 my($name) = @_;
121 8         64 my $path = Path::Tiny->new("_alien/mb/$name");
122 8         254 $path->parent->mkpath;
123 8         1585 $path->touch;
124             }
125              
126              
127             sub ACTION_alien_download
128             {
129 5     5 1 8431 my($self) = @_;
130 5 100       15 return $self if _alien_already_done 'download';
131 4         66 my $build = $self->alien_build;
132 4         57 $build->download;
133 4         2445 $build->checkpoint;
134 4         13877 _alien_touch 'download';
135 4         814 $self;
136             }
137              
138              
139             sub ACTION_alien_build
140             {
141 6     6 1 10903 my($self) = @_;
142 6 100       25 return $self if _alien_already_done 'build';
143 4         143 $self->depends_on('alien_download');
144              
145 4         114 my $build = $self->alien_build;
146 4         56 $build->build;
147              
148 4 50       19141 if($build->meta_prop->{arch})
149             {
150 4         72 my $archdir = Path::Tiny->new("./blib/arch/auto/@{[ join '/', split /-/, $self->dist_name ]}");
  4         25  
151 4         176 $archdir->mkpath;
152 4         1150 my $archfile = $archdir->child($archdir->basename . ".txt");
153 4         216 $archfile->spew('Alien based distribution with architecture specific file in share');
154             }
155              
156             {
157 4         4312 my @parts = split /-/, $self->dist_name;
  4         18  
158 4         64 my $package = join '::', @parts;
159 4         23 my $install_files = Path::Tiny->new("./blib/lib")->child( @parts, 'Install', 'Files.pm' );
160 4         268 $install_files->parent->mkpath;
161 4         1136 $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             );
169             };
170              
171 4         6678 $build->checkpoint;
172              
173 4         21098 _alien_touch 'build';
174 4         674 $self;
175             }
176              
177              
178             sub ACTION_alien_test
179             {
180 2     2 1 4508 my($self) = @_;
181 2         13 $self->depends_on('alien_build');
182              
183 2         70 my $build = $self->alien_build;
184 2 50       30 if($build->can('test'))
185             {
186 2         11 $build->test;
187 1         829 $build->checkpoint;
188             }
189 1         14792 $self;
190             }
191              
192             sub ACTION_test
193             {
194 0     0 0   my($self) = @_;
195 0           $self->depends_on('alien_test');
196 0           $self->SUPER::ACTION_test;
197             }
198              
199             sub ACTION_code
200             {
201 0     0 0   my($self) = @_;
202 0           $self->depends_on('alien_build');
203 0           $self->SUPER::ACTION_code;
204             }
205              
206             1;
207              
208             __END__