.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Package::Pkg 3pm" .TH Package::Pkg 3pm "2012-06-15" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Package::Pkg \- Handy package munging utilities .SH "VERSION" .IX Header "VERSION" version 0.0020 .SH "SYNOPSIS" .IX Header "SYNOPSIS" First, import a new keyword: \f(CW\*(C`pkg\*(C'\fR .PP .Vb 1 \& use Package::Pkg; .Ve .PP Package name formation: .PP .Vb 2 \& pkg\->name( \*(AqXy\*(Aq, \*(AqA\*(Aq ) # Xy::A \& pkg\->name( $object, qw/ Cfg / ); # (ref $object)::Cfg .Ve .PP Subroutine installation: .PP .Vb 1 \& pkg\->install( sub { ... } => \*(AqMyPackage::myfunction\*(Aq ); \& \& # myfunction in MyPackage is now useable \& MyPackage\->myfunction( ... ); .Ve .PP Subroutine exporting: .PP .Vb 1 \& package MyPackage; \& \& use Package::Pkg; \& \& sub this { ... } \& \& # Setup an exporter (literally sub import { ... }) for \& # MyPackage, exporting \*(Aqthis\*(Aq and \*(Aqthat\*(Aq \& pkg\->export( that => sub { ... }, \*(Aqthis\*(Aq ); \& \& package main; \& \& use MyPackage; \& \& this( ... ); \& \& that( ... ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Package::Pkg is a collection of useful, miscellaneous package-munging utilities. Functionality is accessed via the imported \f(CW\*(C`pkg\*(C'\fR keyword, although you can also invoke functions directly from the package (\f(CW\*(C`Package::Pkg\*(C'\fR) .SH "USAGE" .IX Header "USAGE" .SS "pkg\->install( ... )" .IX Subsection "pkg->install( ... )" Install a subroutine, similar to Sub::Install .PP This method takes a number of parameters and also has a two\- and three-argument form (see below) .PP .Vb 3 \& # Install an anonymous subroutine as Banana::magic \& pkg\->install( code => sub { ... } , as => \*(AqBanana::magic\*(Aq ) \& pkg\->install( code => sub { ... } , into => \*(AqBanana::magic\*(Aq ) # Bzzzt! Throws an error! \& \& # Install the subroutine Apple::xyzzy as Banana::magic \& pkg\->install( code => \*(AqApple::xyzzy\*(Aq, as => \*(AqBanana::magic\*(Aq ) \& pkg\->install( code => \*(AqApple::xyzzy\*(Aq, into => \*(AqBanana\*(Aq, as => \*(Aqmagic\*(Aq ) \& pkg\->install( from => \*(AqApple\*(Aq, code => \*(Aqxyzzy\*(Aq, as => \*(AqBanana::magic\*(Aq ) \& pkg\->install( from => \*(AqApple\*(Aq, code => \*(Aqxyzzy\*(Aq, into => \*(AqBanana\*(Aq, as => \*(Aqmagic\*(Aq ) \& \& # Install the subroutine Apple::xyzzy as Banana::xyzzy \& pkg\->install( code => \*(AqApple::xyzzy\*(Aq, as => \*(AqBanana::xyzzy\*(Aq ) \& pkg\->install( code => \*(AqApple::xyzzy\*(Aq, into => \*(AqBanana\*(Aq ) \& pkg\->install( from => \*(AqApple\*(Aq, code => \*(Aqxyzzy\*(Aq, as => \*(AqBanana::xyzzy\*(Aq ) \& pkg\->install( from => \*(AqApple\*(Aq, code => \*(Aqxyzzy\*(Aq, into => \*(AqBanana\*(Aq ) .Ve .PP With implicit \f(CW\*(C`from\*(C'\fR (via \f(CW\*(C`caller()\*(C'\fR) .PP .Vb 1 \& package Apple; \& \& sub xyzzy { ... } \& \& # Install the subroutine Apple::xyzzy as Banana::xyzzy \& pkg\->install( code => \*(Aqxyzzy\*(Aq, as => \*(AqBanana::xyzzy\*(Aq ) # \*(Aqfrom\*(Aq is implicitly \*(AqApple\*(Aq \& pkg\->install( code => \e&xyzzy, as => \*(AqBanana::xyzzy\*(Aq ) .Ve .PP Acceptable parameters are: .PP .Vb 3 \& code A subroutine reference, \& A package\-with\-name identifier, or \& The name of a subroutine in the calling package \& \& from (optional) A package identifier \& If :code is an identifier, then :from is the package where \& the subroutine can be found \& If :code is an identifier and :from is not given, then :from \& is assumed to be the calling package (via caller()) \& \& as The name of the subroutine to install as. Can be a simple name \& (when paired with :into) or a full package\-with\-name \& \& into (optional) A package identifier \& If :as is given, then the full name of the installed \& subroutine is (:into)::(:as) \& \& If :as is not given and we can derive a simple name from \& :code (It is a package\-with\-name identifier), then :as will be \& the name identifier part of :code .Ve .ie n .SS "pkg\->install( $code => $as )" .el .SS "pkg\->install( \f(CW$code\fP => \f(CW$as\fP )" .IX Subsection "pkg->install( $code => $as )" This is the two-argument form of subroutine installation .PP Install \f(CW$code\fR subroutine as \f(CW$as\fR .PP .Vb 1 \& pkg\->install( sub { ... } => \*(AqBanana::xyzzy\*(Aq ) \& \& pkg\->install( \*(AqScalar::Util::blessed\*(Aq => \*(AqBanana::xyzzy\*(Aq ) \& \& pkg\->install( \*(AqScalar::Util::blessed\*(Aq => \*(AqBanana::\*(Aq ) \& \& pkg\->install( sub { ... } => \*(AqBanana::\*(Aq ) # Bzzzt! Throws an error! .Ve .PP \&\f(CW$code\fR should be: .IP "\(bu" 4 A \s-1CODE\s0 reference .Sp .Vb 1 \& sub { ... } .Ve .IP "\(bu" 4 A package-with-name identifier .Sp .Vb 1 \& Scalar::Util::blessed .Ve .IP "\(bu" 4 The name of a subroutine in the calling package .Sp .Vb 1 \& sub xyzzy { ... } \& \& pkg\->install( \*(Aqxyzzy\*(Aq => ... ) .Ve .PP \&\f(CW$as\fR should be: .IP "\(bu" 4 A package-with-name identifier .Sp .Vb 1 \& Acme::Xyzzy::magic .Ve .IP "\(bu" 4 A package identifier (with a trailing ::) .Sp .Vb 1 \& Acme::Xyzzy:: .Ve .ie n .SS "pkg\->install( $code => $into, $as )" .el .SS "pkg\->install( \f(CW$code\fP => \f(CW$into\fP, \f(CW$as\fP )" .IX Subsection "pkg->install( $code => $into, $as )" This is the three-argument form of subroutine installation .PP .Vb 1 \& pkg\->install( sub { ... } => \*(AqBanana\*(Aq, \*(Aqxyzzy\*(Aq ) \& \& pkg\->install( sub { ... } => \*(AqBanana::\*(Aq, \*(Aqxyzzy\*(Aq ) \& \& pkg\->install( \*(AqScalar::Util::blessed\*(Aq => \*(AqBanana\*(Aq, \*(Aqxyzzy\*(Aq ) \& \& pkg\->install( \*(AqScalar::Util::blessed\*(Aq => \*(AqBanana::\*(Aq, \*(Aqxyzzy\*(Aq ) .Ve .PP \&\f(CW$code\fR can be the same as the two argument form .PP \&\f(CW$into\fR should be: .IP "\(bu" 4 A package identifier (trailing :: is optional) .Sp .Vb 1 \& Acme::Xyzzy:: \& \& Acme::Xyzzy .Ve .PP \&\f(CW$as\fR should be: .IP "\(bu" 4 A name (the name of the subroutine) .Sp .Vb 1 \& xyzzy \& \& magic .Ve .ie n .SS "$package = pkg\->name( $part, [ $part, ..., $part ] )" .el .SS "\f(CW$package\fP = pkg\->name( \f(CW$part\fP, [ \f(CW$part\fP, ..., \f(CW$part\fP ] )" .IX Subsection "$package = pkg->name( $part, [ $part, ..., $part ] )" Return a namespace composed by joining each \f(CW$part\fR with \f(CW\*(C`::\*(C'\fR .PP Superfluous/redundant \f(CW\*(C`::\*(C'\fR are automatically cleaned up and stripped from the resulting \f(CW$package\fR .PP If the first part leads with a \f(CW\*(C`::\*(C'\fR, the the calling package will be prepended to \f(CW$package\fR .PP .Vb 2 \& pkg\->name( \*(AqXy\*(Aq, \*(AqA::\*(Aq, \*(Aq::B\*(Aq ) # Xy::A::B \& pkg\->name( \*(AqXy\*(Aq, \*(AqA::\*(Aq ) # Xy::A:: \& \& { \& package Zy; \& \& pkg\->name( \*(Aq::\*(Aq, \*(AqA::\*(Aq, \*(Aq::B\*(Aq ) # Zy::A::B \& pkg\->name( \*(Aq::Xy::A::B\*(Aq ) # Zy::Xy::A::B \& } .Ve .PP In addition, if any part is blessed, \f(CW\*(C`name\*(C'\fR will resolve that part to the package that the part makes reference to: .PP .Vb 2 \& my $object = bless {}, \*(AqXyzzy\*(Aq; \& pkg\->name( $object, qw/ Cfg / ); # Xyzzy::Cfg .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Sub::Install .PP Sub::Exporter .SH "AUTHOR" .IX Header "AUTHOR" Robert Krimen .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2012 by Robert Krimen. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.