-
-
30 Jan 2006 21:29:06 UTC
- Distribution: Class-Tangram
- Module version: 0.02
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (2)
- Testers (467 / 109 / 0)
- Kwalitee
Bus factor: 0- 62.07% Coverage
- License: unknown
- Perl: v5.4.0
- Activity
24 month- Tools
- Download (49.03KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Date::Manip
- Set::Object
- Test::Simple
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Class::Tangram::Generator - Generate Class::Tangram-based objects at runtime.
SYNOPSIS
use Class::Tangram::Generator; my $schema = { ... }; # a Tangram schema definition hashref, # including all classes my $gen = new Class::Tangram::Generator $schema; my $orange = $gen->new('Orange'); $orange->juicyness(10); # $orange is a Class::Tangram-based Orange object
DESCRIPTION
The purpose of Class::Tangram::Generator is to facilitate the rapid development of Class::Tangram-based objects in the Tangram framework. Instead of having to write class modules for all your Tangram objects, many of which only inherit from Class::Tangram for accessor and constraint checking, you use Class::Tangram::Generator to dynamically instantiate each class as necessary, at runtime. This also alleviates the long litany of 'use Orange; use Apple; ... ' statements in all of your scripts.
METHODS
- new($schema, [$base]) [ Class method ]
- new( { Schema => $schema, Base => $base } ) [ Class method ]
-
Initialize and return a new Class::Tangram::Generator object, using the Tangram schema hashref provided. Newly generated objects will have "Class::Tangram" added to their @ISA variable, unless an alternative base class is specified in $base (that way you can subclass Class::Tangram and still use Class::Tangram::Generator).
- new($classname) [ Object method ]
-
Obtain a new object of the provided class. Additional arguments are passed to Class::Tangram's new function (for attribute manipulation). Any errors thrown by Class::Tangram will be propagated by Class::Tangram::Generator.
DISCUSSION
Tangram Schema Extensions
To provide custom methods for each class, add subroutine references to the 'methods' key in the schema:
Orange => { fields => { int => [ qw(juicyness ripeness) ] }, methods => { squeeze => sub { my $self = shift; $self->juicyness($self->juicyness() - 1); }, eviscerate => sub { my $self = shift; $self->juicyness(0); } } }
The subroutines will be automatically installed into the class's namespace.
Interoperation with existing package files
If a .pm module file corresponding to the requested class can be found by Perl (looking in the usual places defined by @INC, PERL5LIB, etc.), it will be loaded before Class::Tangram::Generator has finished dynamically generating the package. This means that any schema and/or methods found in the .pm module file will be overriden by those specified in the schema given to Class::Tangram::Generator. For example, there may be an Orange.pm module file that looks like:
package Orange; sub rehydrate { shift->juicyness(10) } 1;
This allows the addition of more lengthy subroutines without filling up the schema with lots of code. But a "rehydrate" method specified in the schema would entirely replace this subroutine (and it would not be available via SUPER).
EXPORT
Class::Tangram::Generator does not have any methods to export.
HISTORY
AUTHOR
Aaron J Mackey <amackey@virginia.edu>
SEE ALSO
Module Install Instructions
To install Class::Tangram, copy and paste the appropriate command in to your terminal.
cpanm Class::Tangram
perl -MCPAN -e shell install Class::Tangram
For more information on module installation, please visit the detailed CPAN module installation guide.