The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Package::Pkg - Handy package munging utilities

VERSION

version 0.0013

SYNOPSIS

First, import a new keyword: pkg

    use Package::Pkg;

Package name formation:

    pkg->package( 'Xy', 'A' ) # Xy::A
    pkg->package( $object, qw/ Cfg / ); # (ref $object)::Cfg

Subroutine installation:

    pkg->install( sub { ... } => 'MyPackage::myfunction' );

    # myfunction in MyPackage is now useable
    MyPackage->myfunction( ... );

Subroutine exporting:

    package MyPackage;

    use Package::Pkg;

    sub this { ... }

    # Setup an exporter (literally sub import { ... }) for
    # MyPackage, exporting 'this' and 'that'
    pkg->export( that => sub { ... }, 'this' );

    package main;

    use MyPackage;

    this( ... );

    that( ... );

DESCRIPTION

Package::Pkg is a collection of useful, miscellaneous package-munging utilities. Functionality is accessed via the imported pkg keyword, although you can also invoke functions directly from the package (Package::Pkg)

USAGE

install

Install a subroutine, similar to Sub::Install (and actually using that module to do the dirty work)

$package = package( <part>, [ <part>, ..., <part> ] )

Return a namespace composed by joining each <part> with ::

Superfluous/redundant :: are automatically cleaned up and stripped from the resulting $package

If the first part leads with a ::, the the calling package will be prepended to $package

    pkg->package( 'Xy', 'A::', '::B' )      # Xy::A::B
    pkg->package( 'Xy', 'A::' )             # Xy::A::
    
    {
        package Zy;

        pkg->package( '::', 'A::', '::B' )  # Zy::A::B
        pkg->package( '::Xy::A::B' )        # Zy::Xy::A::B
    }

In addition, if any part is blessed, package will resolve that part to the package that the part makes reference to:

    my $object = bless {}, 'Xyzzy';
    pkg->package( $object, qw/ Cfg / );     # Xyzzy::Cfg

export( ... )

Setup an importer in the calling package

Under construction

SEE ALSO

Sub::Install

Sub::Exporter

Class::MOP

AUTHOR

  Robert Krimen <robertkrimen@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Robert Krimen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.