GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  CLASS::TANGRAM::GENERATOR (3)

.ds Aq ’

NAME

Class::Tangram::Generator - Generate Class::Tangram-based objects at runtime.

CONTENTS

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

0.01 Initial release

AUTHOR

Aaron J Mackey <amackey@virginia.edu>

SEE ALSO

Class::Tangram, Tangram, Class::Object, perl.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 CLASS::TANGRAM::GENERATOR (3) 2005-11-29

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.