File Coverage

misc/cpan/MyBuilder.pm
Criterion Covered Total %
statement 21 56 37.5
branch 0 10 0.0
condition 0 3 0.0
subroutine 7 11 63.6
pod 0 3 0.0
total 28 83 33.7


line stmt bran cond sub pod time code
1             package
2             MyBuilder;
3 1     1   7 use strict;
  1         6  
  1         84  
4 1     1   7 use warnings;
  1         2  
  1         125  
5 1     1   611 use utf8;
  1         368  
  1         7  
6              
7 1     1   653 use parent qw(Module::Build);
  1         433  
  1         8  
8              
9 1     1   130289 use Module::CPANfile;
  1         25429  
  1         66  
10              
11 1     1   10 use File::Basename;
  1         2  
  1         232  
12 1     1   9 use File::Spec;
  1         2  
  1         735  
13              
14             sub new {
15 0     0 0   _add_zsh_fpath(
16             shift->SUPER::new(@_)
17             );
18             }
19              
20             sub _add_zsh_fpath {
21 0     0     my ($self) = @_;
22 0           my $elem = 'zsh_fpath';
23 0           $self->add_build_element($elem);
24              
25             # XXX: Is this portable? only tested in Fedora...
26 0           my $zsh_site_fpath = "share/zsh/site-functions";
27 0           my $zsh_vendor_completion = do {
28 0           my $rel = "share/zsh/vendor-completions";
29 0 0         if (-d "/usr/$rel") {
30 0           $rel
31             } else {
32 0           $zsh_site_fpath;
33             }
34             };
35              
36 0           $self->install_base_relpaths($elem => $zsh_site_fpath);
37 0           $self->prefix_relpaths($_ => $elem => $zsh_site_fpath) for qw(site);
38             $self->prefix_relpaths($_ => $elem => $zsh_vendor_completion)
39 0           for qw(core vendor);
40              
41 0           my $installdirs = $self->installdirs;
42 0 0 0       if ($self->install_path($elem)) {
    0          
    0          
43             # Use specified value in Build.PL invocation.
44             }
45             elsif ($installdirs eq 'core' or $installdirs eq 'vendor') {
46 0           $self->install_path($elem => "/usr/$zsh_vendor_completion");
47             }
48             elsif ($installdirs eq 'site') {
49 0           $self->install_path($elem => "/usr/local/$zsh_site_fpath");
50             }
51             else {
52 0           die "Unknown installdirs to derive zsh_fpath: $installdirs";
53             }
54              
55 0           $self;
56             }
57              
58             # sub _default_zsh_fpath {
59             # local $ENV{FPATH};
60             # chomp(my $fpath = qx(zsh -f -c 'print -l \$fpath'));
61             # grep {
62             # m{/site-functions\z}
63             # } split "\n", $fpath;
64             # }
65              
66             # Copied from my YATT::Lite distribution
67             sub my_cpanfile_specs {
68 0     0 0   my ($pack) = @_;
69 0           my $file = Module::CPANfile->load("cpanfile");
70 0           my $prereq = $file->prereq_specs;
71 0           my %args;
72 0           %{$args{requires}} = lexpand($prereq->{runtime}{requires});
  0            
73 0           foreach my $phase (qw/configure runtime build test/) {
74 0           %{$args{$phase . "_requires"}} = lexpand($prereq->{$phase}{requires});
  0            
75             }
76 0           %{$args{recommends}} = (map {lexpand($prereq->{$_}{recommends})}
  0            
  0            
77             keys %$prereq);
78 0           %args
79             }
80              
81             sub lexpand {
82 0 0   0 0   return unless defined $_[0];
83 0           %{$_[0]};
  0            
84             }
85              
86             1;