Decide to throw the question away and name the thing Package Subs. Looks intuitive too and now it fits the recommended practices.
<cite>
Is the name well chosen? I wrote this lightweight Exporter alternative and want to start this tiny thing on CPAN. But it is maybe critizised to much there or it's not worth to stay there. So it is safer to ask here before.
</cite>
1 package Package::Subroutine
2 ; our $VERSION = '0.06'
3
4 ; sub export
5 { my $ns = (caller(1))[0]
6 ; shift() # rm package
7 # working shortcut for __PACKAGE__
8 ; splice(@_,0,1,"".caller) if $_[0] eq '_'
9 ; _import_export($ns,@_)
10 }
11
12 ; sub import
13 { my $ns = (caller(0))[0]
14 ; shift() # rm package
15 ; _import_export($ns,@_)
16 }
17
18 ; sub _import_export
19 { my $namespace = shift
20 ; my $from = shift
21 ; my @methods = @_
22
23 ; for ( @methods )
24 { my $target = "${namespace}::${_}"
25 ; my $source = "${from}::${_}"
26 ; *$target = \&$source
27 }
28 }
29
30 ; sub version
31 { my ($f,$pkg,$num)=@_
32 ; if( defined($num) )
33 { $num=eval { UNIVERSAL::VERSION($pkg,$num) }
34 ; return $@ ? undef : $num
35 }
36 ; eval { UNIVERSAL::VERSION($pkg) }
37 }
38
39 ; sub install
40 { my ($pkg,$target,$name,$coderef)=@_
41 ; $target="${target}::${name}"
42 ; *$target = $coderef
43 }
44
45 ; 1
46
47 __END__
Some hints applied, so the examples using a string are broken. :)
Thank you all to finding this out. :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.