NAME

Gloom::Doc - All About Gloom (the Great Little OO Module)

SYNOPSIS

package MyModule::OO;
do 'MyModule/Gloom.pm';

and:

package MyModule::Foo;
use MyModule::OO -base;

and:

package MyModule::

DESCRIPTION

Gloom is a very small OO module that can be used by CPAN modules that need to be OO, but don't want to add a dependency module to do it.

Gloom provides single inheritance, standard new and init constructor methods, and has attribute accessors. It also turns on strict and warnings automatically.

Gloom is cascading. In other words, using Gloom as a base class for class Foo, enables Foo to later be used as a Gloomy base class. Using the -base syntax invokes all the Gloom functionality.

Accessors

Gloom takes its has accessors from Class::Field, so they are not Moose replicas. They are always read/write. They provide an optional default value as well as an optional initialization code snippet.

package Foo;
use Bar -base;

has 'this';
has 'that' => {};    # Defaults to a hash;
has 'thus', -init => '$self->set_thus';

HOWTO

If I have an OO CPAN module called Foo, I symlink lib/Foo/Gloom.pm to the Gloom.pm in the Gloom repository (see below). (When you make a tarball, Perl turns the symlink into a copied real file.)

Then I create a module called Foo::Base that looks like this:

package Foo::Base;
do 'Foo/Gloom.pm';

That's it. Now I can make Foo::Bar OO like this:

package Foo::Bar;
use Foo::Base -base;
has 'stuff';

and:

package Foo::Bar::Baz;
use Foo::Bar -base;
has 'more_stuff';

WHY DO?

You don't use Gloom, you do it. Gloom.pm has no package statement. Perl's do command will still find it in the @ISA path, but it will eval the code under your package.

REPOSITORY

http://github.com/ingydotnet/gloom-pm

If you use the symlink trick, you'll probably want to checkout this repo next to you other repos.

AUTHOR

Ingy döt Net <ingy@cpan.org>

COPYRIGHT

Copyright (c) 2010. Ingy döt Net.

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

See http://www.perl.com/perl/misc/Artistic.html