Commit | Line | Data |
---|---|---|
a0d0e21e LW |
1 | package subs; |
2 | ||
dca1ad46 | 3 | our $VERSION = '1.03'; |
b75c8c73 | 4 | |
f06db76b AD |
5 | =head1 NAME |
6 | ||
dca1ad46 | 7 | subs - Perl pragma to predeclare subroutine names |
f06db76b AD |
8 | |
9 | =head1 SYNOPSIS | |
10 | ||
11 | use subs qw(frob); | |
12 | frob 3..10; | |
13 | ||
14 | =head1 DESCRIPTION | |
15 | ||
dca1ad46 AC |
16 | This will predeclare all the subroutines whose names are |
17 | in the list, allowing you to use them without parentheses (as list operators) | |
f06db76b AD |
18 | even before they're declared. |
19 | ||
55497cff | 20 | Unlike pragmas that affect the C<$^H> hints variable, the C<use vars> and |
dca1ad46 AC |
21 | C<use subs> declarations are not lexically scoped to the block they appear |
22 | in: they affect | |
23 | the entire package in which they appear. It is not possible to rescind these | |
55497cff | 24 | declarations with C<no vars> or C<no subs>. |
25 | ||
ee580363 | 26 | See L<perlmodlib/Pragmatic Modules> and L<strict/strict subs>. |
f06db76b AD |
27 | |
28 | =cut | |
3fe9a6f1 | 29 | |
a0d0e21e LW |
30 | require 5.000; |
31 | ||
a0d0e21e LW |
32 | sub import { |
33 | my $callpack = caller; | |
34 | my $pack = shift; | |
35 | my @imports = @_; | |
f2b2ac32 | 36 | foreach my $sym (@imports) { |
a0d0e21e LW |
37 | *{"${callpack}::$sym"} = \&{"${callpack}::$sym"}; |
38 | } | |
39 | }; | |
40 | ||
41 | 1; |