Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 5075c87c46
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (44 sloc) 1.357 kB

Objects, Modules and Packages

Package basics

  • A package is a collection of methods
  • Lives in its own namespace
  • Package methods can be exported or called directly
    • Foo::bar()
    • Foo->bar()
    • bar() (if Foo exports it)

Module basics

  • A module is a file containing one or more packages
  • Most people use "module" and "package" interchangably

Object basics

  • An object is a blessed reference to a hash
    • It doesn't have to be a hash reference, but it's most common.
  • Blessing assigns a single class to an object
  • An object can be re-blessed
  • You can muck with the internals, but that doesn't mean you should

1;

  • Modules must end with a true value
  • It doesn't have to be 1
  • Packages don't have the same restriction

@ISA

Perl's object inheritance methods use @ISA to determine what classes a module inherits from. Years ago, inheritance was declared by modifying @ISA directly; now, most programs use the base pragma to declare inheritance.

The following are mostly equivalent:

    package Foo;
    require Wango;
    @ISA = ( "Wango" );

    package Foo;
    use base "Wango";
Jump to Line
Something went wrong with that request. Please try again.