line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package here::install;
|
2
|
3
|
|
|
3
|
|
914
|
use warnings;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
94
|
|
3
|
3
|
|
|
3
|
|
22
|
use strict;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
4
|
3
|
|
|
3
|
|
1010
|
use lib '..';
|
|
3
|
|
|
|
|
926
|
|
|
3
|
|
|
|
|
20
|
|
5
|
3
|
|
|
3
|
|
716
|
use here;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
126
|
|
6
|
|
|
|
|
|
|
|
7
|
0
|
|
|
0
|
0
|
0
|
sub croak {here::croak "here::install: @_"}
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my %installed;
|
10
|
|
|
|
|
|
|
sub import {
|
11
|
18
|
|
|
18
|
|
26
|
shift;
|
12
|
18
|
50
|
|
|
|
70
|
@_ % 2 and croak 'even length list expected';
|
13
|
18
|
|
|
|
|
20
|
my @pseudo;
|
14
|
18
|
|
|
|
|
40
|
while (@_) {
|
15
|
16
|
|
|
|
|
39
|
my ($name, $transform) = splice @_, 0, 2;
|
16
|
|
|
|
|
|
|
|
17
|
16
|
50
|
|
|
|
170
|
$name =~ /^(?:\w+|(?
|
18
|
16
|
50
|
|
|
|
20
|
eval {\&$transform} or croak "in $name => not a subroutine '$transform'";
|
|
16
|
|
|
|
|
46
|
|
19
|
|
|
|
|
|
|
|
20
|
16
|
|
|
|
|
61
|
(my $pkg = "$name.pm") =~ s!::!/!g;
|
21
|
16
|
|
|
|
|
33
|
$INC{$pkg}++;
|
22
|
16
|
|
|
|
|
27
|
$installed{$name} = $pkg;
|
23
|
16
|
|
|
|
|
27
|
push @pseudo, $name;
|
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
3
|
|
22
|
no strict 'refs';
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
242
|
|
26
|
16
|
50
|
|
|
|
17
|
defined &{$name.'::import'} and croak "package '$name' not empty";
|
|
16
|
|
|
|
|
55
|
|
27
|
16
|
|
|
|
|
356
|
*{$name.'::import'} = sub {
|
28
|
3
|
|
|
3
|
|
15
|
use strict;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
870
|
|
29
|
16
|
|
|
16
|
|
914
|
shift;
|
30
|
16
|
|
|
|
|
44
|
@_ = ('here', &$transform);
|
31
|
16
|
|
|
|
|
78
|
goto &here::import;
|
32
|
|
|
|
|
|
|
}
|
33
|
16
|
|
|
|
|
52
|
}
|
34
|
18
|
50
|
|
|
|
24
|
eval {
|
35
|
18
|
|
|
|
|
3137
|
require B::Hooks::EndOfScope;
|
36
|
|
|
|
|
|
|
B::Hooks::EndOfScope::on_scope_end(sub {
|
37
|
18
|
|
|
18
|
|
4541
|
here::install->unimport(@pseudo)
|
38
|
18
|
|
|
|
|
48947
|
});
|
39
|
18
|
|
|
|
|
417
|
1} or warnings::warnif all =>
|
40
|
|
|
|
|
|
|
"B::Hooks::EndOfScope not available, here::install will not have lexical scope\n"
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub unimport {
|
44
|
24
|
|
|
24
|
|
33
|
shift;
|
45
|
24
|
|
|
|
|
64
|
while (@_) {
|
46
|
22
|
|
|
|
|
31
|
my $name = shift;
|
47
|
22
|
50
|
|
|
|
48
|
if (my $pkg = $installed{$name}) {
|
|
0
|
|
|
|
|
|
|
48
|
22
|
|
|
|
|
41
|
delete $INC{$pkg};
|
49
|
3
|
|
|
3
|
|
15
|
no strict 'refs';
|
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
396
|
|
50
|
22
|
|
|
|
|
20
|
delete ${$name.'::'}{'import'};
|
|
22
|
|
|
|
|
312
|
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
else {croak "did not install '$name'"}
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
here::install - easily install compile time transforms
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use here::install 'my::lvalue' => sub {
|
64
|
|
|
|
|
|
|
map "my \$$_; sub $_ ():lvalue {\$$_}" => @_
|
65
|
|
|
|
|
|
|
};
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use my::lvalue qw(foo bar); # my $foo; sub foo ():lvalue {$foo} my $bar; ...
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
foo = 3;
|
70
|
|
|
|
|
|
|
say foo; # 3
|
71
|
|
|
|
|
|
|
say $foo; # 3
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
bar = 4;
|
74
|
|
|
|
|
|
|
say bar++; # 4
|
75
|
|
|
|
|
|
|
say $bar; # 5
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 cleanup
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over 4
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
you can remove the pseudo-modules manually:
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
no here::install 'my::lvalue';
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
or let the declaration fall out of scope if L is installed:
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
{
|
88
|
|
|
|
|
|
|
use here::install ...;
|
89
|
|
|
|
|
|
|
use ...; # works
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
use ...; # error
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SEE ALSO
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
C< here::install > is a wrapper around L.
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
see L for additional examples.
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Eric Strom, C<< >>
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 BUGS
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
please report any bugs or feature requests to C, or
|
108
|
|
|
|
|
|
|
through the web interface at L.
|
109
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on
|
110
|
|
|
|
|
|
|
your bug as I make changes.
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
copyright 2011 Eric Strom.
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
this program is free software; you can redistribute it and/or modify it under
|
117
|
|
|
|
|
|
|
the terms of either: the GNU General Public License as published by the Free
|
118
|
|
|
|
|
|
|
Software Foundation; or the Artistic License.
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
see http://dev.perl.org/licenses/ for more information.
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1
|