Skip to main content

Inside Modules and Packages

  • Chapter
Pro Perl
  • 1157 Accesses

Summary

In this chapter, we explored the insides of modules and packages and how to write our own modules. We saw how packages affect the symbol table and looked at a few ways to take advantage of this knowledge to examine and even manipulate package contents programmatically.

We then looked at Perl’s special phase transition blocks, BEGIN, CHECK, INIT, and END, and how we can use them to create modules that can initialize themselves and carry out various kinds of checks between phases of the interpreter’s operation.

The next main topic discussed was the autoloading mechanism, which allows us to intercept calls to subroutines that do not exist and define them on the fly if we want to. From there we looked at importing and exporting, completing the discussion started in the previous chapter from the viewpoint of the module being imported from. We looked at the basics of the import mechanism, how we can use it to do other things than importing, and how to use the Exporter module to handle many common import and export requirements.

We also looked at package attributes and implementing our own attributes for subroutines and variables with the Attribute::Handlers module. Like the import/export mechanism, this completes the previous discussion started in Chapter 7, where we introduced using Perl’s built-in attributes from the perspective of the implementing module.

Finally, we went through the process of creating an installable module, including the use of h2xs to create the initial working directory and files, bundling the completed module into a distributable archive, and then installing the archive on another platform.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints and permissions

Copyright information

© 2005 Peter Wainwright

About this chapter

Cite this chapter

(2005). Inside Modules and Packages. In: Pro Perl. Apress. https://doi.org/10.1007/978-1-4302-0014-7_10

Download citation

Publish with us

Policies and ethics