Hopen/HopenFileKit.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 108 CC 7 SCAR 22.4
CC
7
Cov
0%
_language_import
30.0
_create_language
6.0
import
6.0
CRAP 9.4
1 # Build::Hopen::HopenFileKit - set up a hopen file
2 package Build::Hopen::HopenFileKit;
3  
4 # What we use
5 use Build::Hopen qw(:default loadfrom);
6 use Build::Hopen::Base;
7 use Build::Hopen::BuildSystemGlobals;
8 use Import::Into;
9 use Package::Alias ();
10  
11 # What we export to the caller
12 use Build::Hopen ();
13 use Build::Hopen::Phases ();
14 use Path::Class ();
15  
16 our $VERSION = '0.000008'; # TRIAL
17  
18 use parent 'Exporter'; # Exporter-exported symbols {{{1
19 our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
20 BEGIN {
21 @EXPORT = qw($__R_on_result *FILENAME);
22 # ^ for Phases::on()
23 # ^ glob so it can be localized
24 @EXPORT_OK = qw();
25 %EXPORT_TAGS = (
26 default => [@EXPORT],
27 all => [@EXPORT, @EXPORT_OK]
28 );
29 } # }}}1
30  
31 # Docs {{{1
32  
33 =head1 NAME
34  
35 Build::Hopen::HopenFileKit - Kit to be used by a hopen file
36  
37 =head1 SYNOPSIS
38  
39 This is a special-purpose test kit used for interpreting hopen files.
40 See L<Build::Hopen::App/_run_phase>. Usage:
41  
42 use Build::Hopen::HopenFileKit "<filename>"[, other args]
43  
44 C<< <filename> >> is the name you want to use for the package using
45 this module, and will be loaded into constant C<$FILENAME> in that
46 package.
47  
48 C<[other args]> are per Exporter, and should be omitted unless you
49 really know what you're doing!
50  
51 =head1 FUNCTIONS
52  
53 =cut
54  
55 # }}}1
56  
57 # Which languages we've loaded
58 my %_loaded_languages;
59  
60 sub _language_import { # {{{1
61  
62 =head2
63  
64 C<import()> routine for the fake "language" package
65  
66 =cut
67  
68 my $target = caller;
69 #say "language invoked from $target";
70 shift; # Drop our package name
71 croak "I need at least one language name" unless @_;
72  
73 die "TODO permit aliases" if ref $_[0]; # TODO take { alias => name }
74  
75 foreach my $language (@_) {
76 next if $_loaded_languages{$language};
77 # Only load any given language once. This avoids cowardly warnings
78 # from Package::Alias, but still causes warnings if a language
79 # overrides an unrelated package. (For example, saying
80 # `use language "Graph"` would be a Bad Idea :) .)
81  
82 # Find the package for the given language
83 my ($src_package, $dest_package);
84 $src_package = loadfrom($language, "${Toolset}::", '')
85 or croak "Can't find a package for language ``$language'' " .
86 "in toolset ``$Toolset''";
87  
88 # Import the given language into the root namespace.
89 # Use only the last ::-separated component if :: are present.
90 $dest_package = ($src_package =~ m/::([^:]+)$/) ? $1 : $src_package;
91 Package::Alias->import::into($target, $dest_package => $src_package);
92  
93 $_loaded_languages{$language} = true;
94 } #foreach requested language
95 } #_language_import }}}1
96  
97 sub _create_language { # {{{1
98  
99 =head2
100  
101 Create a package "language" so that the calling package can invoke it.
102  
103 =cut
104  
105 #say "_create_language";
106 return if %language::; #idempotent
107  
108 {
109 no strict 'refs';
110 *{'language::import'} = \&_language_import;
111 }
112  
113 $INC{'language.pm'} = 1;
114 } #_create_language() }}}1
115  
116 sub import { # {{{1
117  
118 =head2 import
119  
120 Set up the calling package. See L</SYNOPSIS> for usage.
121  
122 =cut
123  
124 my $target = caller;
125 my $target_friendly_name = $_[1] or croak "Need a filename";
126 # 0=__PACKAGE__, 1=filename
127 my @args = splice @_, 1, 1;
128 # Remove the filename; leave the rest of the args for Exporter's use
129  
130 # Export our stuff
131 __PACKAGE__->export_to_level(1, @args);
132  
133 # Re-export packages
134 $_->import::into($target) foreach qw(Build::Hopen::Base Path::Class
135 Build::Hopen::BuildSystemGlobals);
136 Build::Hopen->import::into($target, ':all');
137 Build::Hopen::Phases->import::into($target, qw(:all :hopenfile));
138  
139 # Initialize data in the caller
140 {
141 no strict 'refs';
142 *{ $target . '::FILENAME' } = eval("\\\"$target_friendly_name\"");
143 # Need `eval` to make it read-only - even \"$target..." isn't RO
144 }
145  
146 # Create packages at the top level
147 _create_language();
148 Package::Alias->import::into($target, 'H' => 'Build::Hopen::H')
149 unless eval { scalar keys %H:: };
150 # Don't import twice, but without the need to set Package::Alias::BRAVE
151 } #import() # }}}1
152  
153 1;
154 __END__