Codebase list libextutils-depends-perl / 957bdb2
Doc, test, implement load() using *::I::F->Inline() et al. Ed J 9 years ago
2 changed file(s) with 59 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
197197 $instpath = File::Spec->rel2abs ($instpath);
198198 }
199199
200 my @typemaps = map {
201 File::Spec->rel2abs ($_, $instpath)
202 } @{"$depinstallfiles\::typemaps"};
200 my (@typemaps, $inc, $libs, @deps);
201
202 @deps = eval { $depinstallfiles->deps };
203 @deps = @{"$depinstallfiles\::deps"}
204 if $@ and exists ${"$depinstallfiles\::"}{deps};
205
206 my $inline = eval { $depinstallfiles->Inline('C') };
207 if (!$@) {
208 $inc = $inline->{INC} // '';
209 $libs = $inline->{LIBS} // '';
210 @typemaps = @{ $inline->{TYPEMAPS} || [] };
211 } else {
212 $inc = ${"$depinstallfiles\::inc"} // '';
213 $libs = ${"$depinstallfiles\::libs"} // '';
214 @typemaps = @{"$depinstallfiles\::typemaps"};
215 }
216 @typemaps = map { File::Spec->rel2abs ($_, $instpath) } @typemaps;
203217
204218 {
205219 instpath => $instpath,
206220 typemaps => \@typemaps,
207 inc => "-I$instpath ".${"$depinstallfiles\::inc"},
208 libs => ${"$depinstallfiles\::libs"},
221 inc => "-I$instpath $inc",
222 libs => $libs,
209223 # this will not exist when loading files from old versions
210224 # of ExtUtils::Depends.
211 (exists ${"$depinstallfiles\::"}{deps}
212 ? (deps => \@{"$depinstallfiles\::deps"})
213 : ()),
225 deps => \@deps,
214226 }
215227 }
216228
600612 =back
601613
602614 If you want to make module I<name> support this, you must provide
603 a module I<name>::Install::Files, which on loading will provide the
604 following package variables: C<@typemaps>, C<$inc>, C<$libs>, C<$deps>,
605 with the same contents as above (not coincidentally). The C<load>
606 function will supply the C<instpath>. An easy way to achieve this is
607 to use the method L</"$depends-E<gt>save_config ($filename)">, but your
608 package may have different facilities already.
615 a module I<name>::Install::Files, which on loading will implement the
616 following class methods:
617
618 $hashref = name::Install::Files->Inline('C');
619 # hash to contain any necessary TYPEMAPS (array-ref), LIBS, INC
620 @deps = name::Install::Files->deps;
621 # any modules on which "name" depends
622
623 An easy way to achieve this is to use the method
624 L</"$depends-E<gt>save_config ($filename)">, but your package may have
625 different facilities already.
609626
610627 =item $depends->load_deps
611628
3838 my @installed_files = qw(dep.h
3939 dep-private.h);
4040 $dep_info->install (@installed_files);
41
42 my $INC_FRAG = '-Ddistinctive';
43 map { make_fake($_) } qw(Fakenew Fakeold);
44 sub Fakenew::Install::Files::Inline { +{ INC => $INC_FRAG } }
45 sub Fakenew::Install::Files::deps { qw(Fakeold) }
46 {
47 no warnings 'once';
48 @Fakeold::Install::Files::deps = qw(Fakenew);
49 $Fakeold::Install::Files::inc = $INC_FRAG;
50 $Fakeold::Install::Files::libs = '';
51 }
52 sub make_fake {
53 my $class = shift . '::Install::Files';
54 my @pieces = split '::', $class;
55 require File::Spec;
56 my $pm = join('/', @pieces) . '.pm';
57 $INC{$pm} = File::Spec->catdir(qw(build fake), split '/', $pm);
58 }
59 sub test_load {
60 my ($info, $msg) = @_;
61 my $install_part = qr|Fake.*Install|;
62 like ($info->{inc}, $install_part, "$msg inc generic");
63 like ($info->{inc}, qr/$INC_FRAG/, "$msg inc specific");
64 ok (scalar(grep { /Fake/ } @{$info->{deps}}), $msg);
65 ok (exists $info->{libs}, $msg);
66 }
67 test_load (ExtUtils::Depends::load('Fakenew'), 'load new scheme');
68 test_load (ExtUtils::Depends::load('Fakeold'), 'load old scheme');
4169
4270 use Data::Dumper;
4371 $Data::Dumper::Terse = 1;