Winfried Trumper > Object-By > Object::By::Scalar

Download:
Object-By-v0.08.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Object::By::Scalar - minimalistic constructors for scalar based objects

SYNOPSIS ^

        package some_package;
        use parent qw(Object::By::Scalar);

        sub _constructor {
                my ($this, ...) = @_;
                $$this = data of the only attribute;
                ...
                return;
        }

        package main;
        use some_package;
        some_package->constructor(...);

DESCRIPTION ^

Object::By::Scalar provides generic constructors for OO programming, which are tailored to an actual class via a method called _constructor. A generic constructor creates the reference from various sources, blesses, tailors, and finally returns it. A small advantage at a small price of 60 lines of Perl code.

METHOD REFERENCE (API) ^

The design goal was a simple and robust API with a straightforward implementation, respecting all limitations of Perl 5.

$class->constructor or class->constructor

A generic constructor for objects of the class. Calls _constructor and forwards any arguments to it.

$object->_constructor

A standard tailoring, which stores the scalar value of first argument to _constructor() as the scalar value. Normally called internally only, but can be used to initialize prototype objects.

$class->prototype_constructor or class->prototype_constructor

Prototype means, the object only carries a class and no data. Otherwise like class->constructor.

$old_object->sibling_constructor

Takes the class of $old_object to create an object of the same class. Otherwise works like class->constructor.

$old_object->clone_constructor

Takes the class of $old_object to create an object of the same class and the same data. Does not call _constructor, but copies the first level of the object's data structure. To leave no doubt: no deep copy is performed.

For a way to use partial class names for object construction, see Package::Aspect::Wild_Class.

SUPPORTING CLASSES ^

These have no documentation of their own. These should come before Object::By::Scalar in order to override any default methods.

Object::By::Scalar_Accessor

Provides the generic methods _get, _set and _get_or_set.

KNOWN BUGS AND LIMITATIONS ^

There are no tests.

There are numerous far more advanced approaches for generic constructors available on CPAN.

This module has been developed for the specific needs of FReDI and the Mica Environment. It is used by Mica, HTTP::Fools_Gold, Package::Aspect, Text::Placeholder and Object::Episode.

AUTHOR ^

Winfried Trumper <pub+perl(a)wt.tuxomania.net>

COPYRIGHT AND LICENSE ^

Copyright (C) 2011,2012 Winfried Trumper

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

syntax highlighting: