Object::Trampoline

Object::Trampoline is a Perl module for delay object construction.
Download

Object::Trampoline Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Steven Lembark
  • Publisher web site:
  • http://search.cpan.org/~lembark/

Object::Trampoline Tags


Object::Trampoline Description

Object::Trampoline is a Perl module for delay object construction. Object::Trampoline is a Perl module for delay object construction, and optionally using the class' module, until a method is actually dispatched, simplifies runtime definition of handler classes.SYNOPSIS # adding "use_class" will perform an "eval use $class" # at the point where the object is first accessed. use Object::Trampoline; # the real class name is added to the normal constructor # and 'Object::Trampoline' used instead. the destination # class' constructor is called when object is actually # used for something. my $dbh = Object::Trampoline->connect( 'DBI', $dsn, $user, $pass, $conf ); my $sth = $dbh->prepare( 'select foo from bar' ); # or specify the package and args from a config file # or via inherited data. # # the constructor lives in the destination class # and has nothing to do with Object::Trampoline. my %config = Config->read( $config_file_path ); my ( $class, $const, @argz ) = @config{ qw( class const args ) }; my $handle = Object::Trampoline->$const( $class, @argz ); # at this point ref $handle is 'Object::Trampoline::Bounce'. $handle->frobnicate( @stuff ); # at this point ref $handle is $class # there are times when it is helpful to delay using # the object's class module until the object is # instantiated. O::T::U adds the caller's package # and a "use $class" before the constructor. my $lazy = Object::Trampoline::Use->frobnicate( $class, @stuff ); my $result = $lazy->susan( 'dessert' );There are times when constructing an object is expensive or has to be delayed -- database handles in heavily forked apache servers are one example. This module creates a "trampoline" object: when called it replaces the object you have with the object you want. The module itself consists only of two AUTOLOADS: one with captures the constructor call, the other the first method call. The first class blesses a closure which creates the necessary object into the second class, which replces $_ with a new object and re-dispatches the call into the proper class.Using an autoload as the constructor allows Object::Trampoline to use whatever constructor name the "real" class uses without having to pass it as another argument. Requirements: · Perl


Object::Trampoline Related Software