SlideShare a Scribd company logo
Object::Trampoline

 When having not the object you want 
         is what you need.




          Steven Lembark
      <lembark@wrkhors.com>
Er... what's “trampoline” object?
●
    Trampolines not the object you want.
●
    They are a proxy for the constructor of another 
    object – the one you want.
●
    Their behavior is replacing themselves when you 
    call a method on them.
●
    Aside from calling a separate constructor, the user 
    shouldn't know the trampoline ever existed.
Why bother?
●
    When you don't want an object until you need it:
    –   Connections to servers that not always used/available 
        (e.g., during development or unit testing).
    –   Avoid construcing expensive, seldom­used objects.
    –    Delay connections to back­end servers until necessary.
●
    Think of starting up a heavily­forked apache server 
    and not bringing your database to its knees.
●
    Or not parsing really large XML until you use it.
WARNING:

The code you are about to see 
  contains graphic AUTOLOAD, 
  literal blessing, and re­
assignment of stack variables.



 Parenthetical discresion is 
          advised.
How do you bounce an object?
●
    Easily, in Perl (pity the poor slobs using Java!).
    –   Perl's AUTOLOAD mechanism allows you to intercept 
        method calls cleanly.
    –   Passing arguments by reference allows replacing them on 
        the stack: assigning to $_[0] gives your caller a new 
        object on the fly.
    –   “goto &sub” replaces one call with another.
●
    Result:  a re­dispatched call with a new object.
Co­Operating Classes
●
    The Object::Trampoline (“O::T”) module uses two 
    classes: a constructor and dispatcher.
●
    O::T itself is nothing but an AUTOLOAD.
●
    It returns a closure blessed into 
    Object::Trampoline::Bounce (“O::T::B”).
●
    O::T::B is nothing but (surprise!) an AUTOLOAD. 
●
    O::T::B replaces the object, re­dispatches the call.
Replacing an Object
●
    O::T::B::AUTOLOAD begins by replacing the stack 
    argument with the result of running itself:
          $_[0] = $_[0]­>();

    ●
        This replaces the caller's copy of the object with a 
        delayed call to the constructor.
    ●
        This new object is then used to locate the 
        requested subroutine via “can”.
Using Object::Trampoline
●
    The difference you'll see in using a trampoline 
    object is in the constructor.
●
    The 'real' class becomes the first argument, and 
    “Object::Trampoline” becomes the new class:

my $dbh = DBI­>connect( $dsn,@argz);

becomes:

my $dbh = Object::Tram poline ‑>connect
( 'DBI', $dsn, @argz );
Under the hood
 ●
     O::T's AUTOLOAD handles the construction by 
     blessing a closure that does the real work:
my ( undef, $class, @argz ) = @_;


my $meth = ( split $AUTOLOAD, '::' )[­1];


my $sub  = sub { $class­>$meth( @argz ) };


bless $sub, 'Object::Trampoline::Bounce'
Using the object
 ●
     At this point the caller gets back what looks like an 
     ordinary object:
# $dbh starts out as a trampoline


my $dbh = 
Object::Trampoline‑>connect( 'DBI', ... );


# the method call converts it to a DBI object.


my $sth = $dbh­>prepare( ... );


# from this point on there's no way to tell 
# that $dbh wasn't a DBI object all along.
Converting the Object
●
    The assignment to $_[0] is made in 
    O::T::B::AUTOLOAD.
●
    If $_[0]­>can( $method ) then it uses goto, 
    otherwise it has to try $_[0]­>$method( @argz ) and 
    hope for the best (e.g., another AUTOLOAD).
●
    It also has contains a stub DESTROY to avoid 
    constructing objects when the go out of scope.
Object::Trampoline::Bounce
our $AUTOLOAD = '';
AUTOLOAD
{
    $_[0] = $_[0]­>();
    my $class  = ref $_[0];
    my $method = ( split /::/, $AUTOLOAD )[ ­1 ];
    if( my $sub = $_[0]­>can( $method ) )
    {
        goto &$sub
    }
    else
    {
        my $obj = shift;
        $obj­>$method( @_ )
    }
}


DESTROY {}
But wait, there's more!
●
    What if requiring the module is the expensive part?
●
    You want to delay the “use” until necessary, not just 
    the construction?
●
    Object::Trampoline::Use does exactly that:
    my sub
    = sub
    {
        eval “package $caller; use $class;


        $class­>$method( @argz )
    };
Why use a closure?
●
    I could have stored the arguments in a hash, with 
    $object­>{ class } and $object­>{ arguments }.
●
    But then there would be a difference in handling 
    different objects that came from O::T or O::T::U.
●
    The closure allows each handler class to handle the 
    construction its own way without to specialize 
    O::T::B for each of them.
Example: Server Handles
●
    Centralizing the data for your server handles can be 
    helpful.
●
    All of the mess for describing DBI, Syslog, HTTP, 
    SOAP... connections can be pushed into one place.
●
    Catch: Not all of the servers are always available, or 
    necessary.
●
    Fix: Export trampolines.
Server::Handles
package Server::Handle;
use Server::Configure
qw
(
     dbi_user ...
     syslog_server ...
);
my %handlerz =
(
     dbh     =>
     Object::Trampoline‑>connect( 'DBI', ... ),


     syslogh =>
     Object::Trampoline‑>openlog( 'Syslog::Wrapper', ... ),
);
sub import
{
   # push the handlers out as­is via *$glob = $value.
   # the values are shared and the first place they are
   # used bounces them for the entire process
}
Trampoline as a Factory
●
    This cannot be avoided, therefore it is a feature.
●
    Unwrapping the stack into a lexical before calling a 
    method on the trampoline updates the lexical, not 
    the caller's copy.
    $foo­>my_wrapper;


    sub my_wrapper
    {
        my $obj    = shift; # my_wrapper copy of $foo


        $obj­>some_method;  # updates $obj, not $foo
Caveat Utilitor
●
    Trampoline objects can only dispatch methods.
●
    If your object is tied then it'll blow up if you try to 
    access its tied interface:
    –   $dbh­>{ AutoCommit } = 0; # dies here for trampoline
●
    None of the ways around this are transparent to the 
    user, but even with DBI the simple fix is to use 
    methods to configure the object.
“ref” is not a method
●
    Until a method is called, “ref $object” will give you 
    “Object::Trampoline::Bounce” and “reftype” will 
    give you back “CODE”.
●
    This mainly affects the use of inside­out data, since 
    $object_data{ refaddr $object } will change after the 
    first method call.
Prototypes are Evil.
●
    Notice the closure:                                                       
             $class­>$constructor( @argz )
●
    Defining $constructor with a prototype of ($$) will 
    break even if you have two values in @argz!
●
    <soapbox>                                                               
    Add code or use Class::Contract (whatever) to 
    actually validate the arguments. Breaking Perl's 
    calling convention only causes pain.         
    </soapbox>.

More Related Content

PPTX
Ampersandjs
Drew Fyock
 
PDF
Code me a HR
Arnaud Langlade
 
PDF
Best practices for crafting high quality PHP apps (Bulgaria 2019)
James Titcumb
 
PPTX
AngularJS Animations
Eyal Vardi
 
PDF
Fórum de Software Livre do Serpro RJ 2009
Fabio Akita
 
PPTX
Testing ASP.net Web Applications using Ruby
Ben Hall
 
PDF
Javascript Everywhere
elliando dias
 
PPTX
PHP Array very Easy Demo
Salman Memon
 
Ampersandjs
Drew Fyock
 
Code me a HR
Arnaud Langlade
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
James Titcumb
 
AngularJS Animations
Eyal Vardi
 
Fórum de Software Livre do Serpro RJ 2009
Fabio Akita
 
Testing ASP.net Web Applications using Ruby
Ben Hall
 
Javascript Everywhere
elliando dias
 
PHP Array very Easy Demo
Salman Memon
 

What's hot (20)

PDF
GDayX - Advanced Angular.JS
Nicolas Embleton
 
PPT
Introduction to Prototype JS Framework
Mohd Imran
 
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
PDF
Intro to Angular.JS Directives
Christian Lilley
 
KEY
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
PDF
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
PDF
Crafting Quality PHP Applications (PHP Benelux 2018)
James Titcumb
 
PDF
The Beauty of Java Script
Michael Girouard
 
PDF
Writing JavaScript that doesn't suck
Ross Bruniges
 
PDF
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
James Titcumb
 
PDF
Advanced javascript
Doeun KOCH
 
PPTX
jQuery PPT
Dominic Arrojado
 
PPTX
AngularJs $provide API internals & circular dependency problem.
Yan Yankowski
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
James Titcumb
 
PPTX
Testing ASP.net Web Applications using Ruby
Ben Hall
 
PDF
Crafting Quality PHP Applications (ConFoo YVR 2017)
James Titcumb
 
PPTX
AngularJS Architecture
Eyal Vardi
 
PPTX
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
PDF
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
GDayX - Advanced Angular.JS
Nicolas Embleton
 
Introduction to Prototype JS Framework
Mohd Imran
 
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
Intro to Angular.JS Directives
Christian Lilley
 
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
Crafting Quality PHP Applications (PHP Benelux 2018)
James Titcumb
 
The Beauty of Java Script
Michael Girouard
 
Writing JavaScript that doesn't suck
Ross Bruniges
 
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
James Titcumb
 
Advanced javascript
Doeun KOCH
 
jQuery PPT
Dominic Arrojado
 
AngularJs $provide API internals & circular dependency problem.
Yan Yankowski
 
The Beauty Of Java Script V5a
rajivmordani
 
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
James Titcumb
 
Testing ASP.net Web Applications using Ruby
Ben Hall
 
Crafting Quality PHP Applications (ConFoo YVR 2017)
James Titcumb
 
AngularJS Architecture
Eyal Vardi
 
JavaScript APIs you’ve never heard of (and some you have)
Nicholas Zakas
 
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
Ad

Similar to Object Trampoline (20)

PDF
Object::Trampoline: Follow the bouncing object.
Workhorse Computing
 
PDF
Object Trampoline: Why having not the object you want is what you need.
Workhorse Computing
 
PDF
Lazy Data Using Perl
Workhorse Computing
 
PDF
Object::Franger: Wear a Raincoat in your Code
Workhorse Computing
 
KEY
Introduction To Moose
Mike Whitaker
 
PDF
Working Effectively With Legacy Perl Code
erikmsp
 
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
PDF
Object Exercise
Workhorse Computing
 
PDF
Perl5 meta programming
karupanerura
 
PDF
Moo at System::Image::Update
Jens Rehsack
 
ODP
Moose - YAPC::NA 2012
xSawyer
 
ODP
Moose: Perl Objects
Lambert Lum
 
PDF
Perl object ?
ℕicolas ℝ.
 
PDF
mro-every.pdf
Workhorse Computing
 
PPT
web programming Unit VI PPT by Bhavsingh Maloth
Bhavsingh Maloth
 
ODP
Object-Oriented Programming with Perl and Moose
Dave Cross
 
PPT
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 
PDF
Perl objects 101
Craig Treptow
 
PDF
PHP 5
Rafael Corral
 
Object::Trampoline: Follow the bouncing object.
Workhorse Computing
 
Object Trampoline: Why having not the object you want is what you need.
Workhorse Computing
 
Lazy Data Using Perl
Workhorse Computing
 
Object::Franger: Wear a Raincoat in your Code
Workhorse Computing
 
Introduction To Moose
Mike Whitaker
 
Working Effectively With Legacy Perl Code
erikmsp
 
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Object Exercise
Workhorse Computing
 
Perl5 meta programming
karupanerura
 
Moo at System::Image::Update
Jens Rehsack
 
Moose - YAPC::NA 2012
xSawyer
 
Moose: Perl Objects
Lambert Lum
 
Perl object ?
ℕicolas ℝ.
 
mro-every.pdf
Workhorse Computing
 
web programming Unit VI PPT by Bhavsingh Maloth
Bhavsingh Maloth
 
Object-Oriented Programming with Perl and Moose
Dave Cross
 
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 
Perl objects 101
Craig Treptow
 
Ad

More from Workhorse Computing (20)

PDF
Wheels we didn't re-invent: Perl's Utility Modules
Workhorse Computing
 
PDF
Paranormal statistics: Counting What Doesn't Add Up
Workhorse Computing
 
PDF
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
PDF
Unit Testing Lots of Perl
Workhorse Computing
 
PDF
Generating & Querying Calendar Tables in Posgresql
Workhorse Computing
 
PDF
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
PDF
BSDM with BASH: Command Interpolation
Workhorse Computing
 
PDF
Findbin libs
Workhorse Computing
 
PDF
Memory Manglement in Raku
Workhorse Computing
 
PDF
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
PDF
Effective Benchmarks
Workhorse Computing
 
PDF
Metadata-driven Testing
Workhorse Computing
 
PDF
The W-curve and its application.
Workhorse Computing
 
PDF
Keeping objects healthy with Object::Exercise.
Workhorse Computing
 
PDF
Perl6 Regexen: Reduce the line noise in your code.
Workhorse Computing
 
PDF
Smoking docker
Workhorse Computing
 
PDF
Getting Testy With Perl6
Workhorse Computing
 
PDF
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Workhorse Computing
 
PDF
Neatly folding-a-tree
Workhorse Computing
 
PDF
Light my-fuse
Workhorse Computing
 
Wheels we didn't re-invent: Perl's Utility Modules
Workhorse Computing
 
Paranormal statistics: Counting What Doesn't Add Up
Workhorse Computing
 
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
Unit Testing Lots of Perl
Workhorse Computing
 
Generating & Querying Calendar Tables in Posgresql
Workhorse Computing
 
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
BSDM with BASH: Command Interpolation
Workhorse Computing
 
Findbin libs
Workhorse Computing
 
Memory Manglement in Raku
Workhorse Computing
 
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Effective Benchmarks
Workhorse Computing
 
Metadata-driven Testing
Workhorse Computing
 
The W-curve and its application.
Workhorse Computing
 
Keeping objects healthy with Object::Exercise.
Workhorse Computing
 
Perl6 Regexen: Reduce the line noise in your code.
Workhorse Computing
 
Smoking docker
Workhorse Computing
 
Getting Testy With Perl6
Workhorse Computing
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Workhorse Computing
 
Neatly folding-a-tree
Workhorse Computing
 
Light my-fuse
Workhorse Computing
 

Recently uploaded (20)

PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Software Development Methodologies in 2025
KodekX
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Doc9.....................................
SofiaCollazos
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 

Object Trampoline

  • 2. Er... what's “trampoline” object? ● Trampolines not the object you want. ● They are a proxy for the constructor of another  object – the one you want. ● Their behavior is replacing themselves when you  call a method on them. ● Aside from calling a separate constructor, the user  shouldn't know the trampoline ever existed.
  • 3. Why bother? ● When you don't want an object until you need it: – Connections to servers that not always used/available  (e.g., during development or unit testing). – Avoid construcing expensive, seldom­used objects. –  Delay connections to back­end servers until necessary. ● Think of starting up a heavily­forked apache server  and not bringing your database to its knees. ● Or not parsing really large XML until you use it.
  • 4. WARNING: The code you are about to see  contains graphic AUTOLOAD,  literal blessing, and re­ assignment of stack variables. Parenthetical discresion is  advised.
  • 5. How do you bounce an object? ● Easily, in Perl (pity the poor slobs using Java!). – Perl's AUTOLOAD mechanism allows you to intercept  method calls cleanly. – Passing arguments by reference allows replacing them on  the stack: assigning to $_[0] gives your caller a new  object on the fly. – “goto &sub” replaces one call with another. ● Result:  a re­dispatched call with a new object.
  • 6. Co­Operating Classes ● The Object::Trampoline (“O::T”) module uses two  classes: a constructor and dispatcher. ● O::T itself is nothing but an AUTOLOAD. ● It returns a closure blessed into  Object::Trampoline::Bounce (“O::T::B”). ● O::T::B is nothing but (surprise!) an AUTOLOAD.  ● O::T::B replaces the object, re­dispatches the call.
  • 7. Replacing an Object ● O::T::B::AUTOLOAD begins by replacing the stack  argument with the result of running itself: $_[0] = $_[0]­>(); ● This replaces the caller's copy of the object with a  delayed call to the constructor. ● This new object is then used to locate the  requested subroutine via “can”.
  • 8. Using Object::Trampoline ● The difference you'll see in using a trampoline  object is in the constructor. ● The 'real' class becomes the first argument, and  “Object::Trampoline” becomes the new class: my $dbh = DBI­>connect( $dsn,@argz); becomes: my $dbh = Object::Tram poline ‑>connect ( 'DBI', $dsn, @argz );
  • 9. Under the hood ● O::T's AUTOLOAD handles the construction by  blessing a closure that does the real work: my ( undef, $class, @argz ) = @_; my $meth = ( split $AUTOLOAD, '::' )[­1]; my $sub  = sub { $class­>$meth( @argz ) }; bless $sub, 'Object::Trampoline::Bounce'
  • 10. Using the object ● At this point the caller gets back what looks like an  ordinary object: # $dbh starts out as a trampoline my $dbh =  Object::Trampoline‑>connect( 'DBI', ... ); # the method call converts it to a DBI object. my $sth = $dbh­>prepare( ... ); # from this point on there's no way to tell  # that $dbh wasn't a DBI object all along.
  • 11. Converting the Object ● The assignment to $_[0] is made in  O::T::B::AUTOLOAD. ● If $_[0]­>can( $method ) then it uses goto,  otherwise it has to try $_[0]­>$method( @argz ) and  hope for the best (e.g., another AUTOLOAD). ● It also has contains a stub DESTROY to avoid  constructing objects when the go out of scope.
  • 13. But wait, there's more! ● What if requiring the module is the expensive part? ● You want to delay the “use” until necessary, not just  the construction? ● Object::Trampoline::Use does exactly that: my sub = sub {     eval “package $caller; use $class;     $class­>$method( @argz ) };
  • 14. Why use a closure? ● I could have stored the arguments in a hash, with  $object­>{ class } and $object­>{ arguments }. ● But then there would be a difference in handling  different objects that came from O::T or O::T::U. ● The closure allows each handler class to handle the  construction its own way without to specialize  O::T::B for each of them.
  • 15. Example: Server Handles ● Centralizing the data for your server handles can be  helpful. ● All of the mess for describing DBI, Syslog, HTTP,  SOAP... connections can be pushed into one place. ● Catch: Not all of the servers are always available, or  necessary. ● Fix: Export trampolines.
  • 16. Server::Handles package Server::Handle; use Server::Configure qw ( dbi_user ... syslog_server ... ); my %handlerz = ( dbh     => Object::Trampoline‑>connect( 'DBI', ... ), syslogh => Object::Trampoline‑>openlog( 'Syslog::Wrapper', ... ), ); sub import {    # push the handlers out as­is via *$glob = $value.    # the values are shared and the first place they are    # used bounces them for the entire process }
  • 17. Trampoline as a Factory ● This cannot be avoided, therefore it is a feature. ● Unwrapping the stack into a lexical before calling a  method on the trampoline updates the lexical, not  the caller's copy. $foo­>my_wrapper; sub my_wrapper {     my $obj    = shift; # my_wrapper copy of $foo     $obj­>some_method;  # updates $obj, not $foo
  • 18. Caveat Utilitor ● Trampoline objects can only dispatch methods. ● If your object is tied then it'll blow up if you try to  access its tied interface: – $dbh­>{ AutoCommit } = 0; # dies here for trampoline ● None of the ways around this are transparent to the  user, but even with DBI the simple fix is to use  methods to configure the object.
  • 19. “ref” is not a method ● Until a method is called, “ref $object” will give you  “Object::Trampoline::Bounce” and “reftype” will  give you back “CODE”. ● This mainly affects the use of inside­out data, since  $object_data{ refaddr $object } will change after the  first method call.
  • 20. Prototypes are Evil. ● Notice the closure:                                                                 $class­>$constructor( @argz ) ● Defining $constructor with a prototype of ($$) will  break even if you have two values in @argz! ● <soapbox>                                                                Add code or use Class::Contract (whatever) to  actually validate the arguments. Breaking Perl's  calling convention only causes pain.          </soapbox>.