Author image Eric Wilhelm
and 1 contributors


Package::Tent - temporary package infrastructure


This module allows you to setup camp inside an existing module/program with minimal commitment to filenames, while still being able to use the same require/use statements of normal code.

  use Package::Tent sub {
    package Who::sYourDaddy;
    sub thing {
      print "hello world\n";
  use Package::Tent sub {
    package What::sInAName;
    use base 'Who::sYourDaddy';
    sub method {

  use What::sInAName;


The 'use Package::Tent sub {...}' statement is equivalent to wrapping your package in a BEGIN block and setting an entry in %INC.

Note that the first example simply returns a true value, while the second explicitly returns the package name using the __PACKAGE__ token. You may use either method.

The implicit form will cause Package::Tent to attempt opening and scanning the file containing the calling code. The latter is more robust in strange (PAR, @INC hooks, etc.) environments, but is less convenient.


It is not wise to install a datacenter in a tent. Need I say more?

This module was designed to reduce development time by allowing me to maintain my train of thought. The scenario is that you're coding along in some module or program and you realize the need for a support module (or even a few of them.) Package::Tent allows you to keep writing code while you're thinking rather than stopping long enough to commit to a name, create a file, maybe add it to version control, etc.

It should be similarly useful in single-file prototypes or other experimental code. Hopefully, lowering the file-juggling overhead encourages you to start your code with a modular style. When the prototype becomes the finished product (as it so often does), the refactoring is nearly mechanical as opposed to a difficult untangling of ad-hoc variables.



  use Package::Tent sub {



  Package::Tent->_find_package($file, $line);


Eric Wilhelm @ <ewilhelm at cpan dot org>


If you found this module on CPAN, please report any bugs or feature requests through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

If you pulled this development version from my /svn/, please contact me directly.


Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved.


Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.


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