[Chicago-talk] Shortening a module name

brian d foy brian.d.foy at gmail.com
Mon Feb 20 16:15:12 PST 2006

On 2/20/06, Jay Strauss <me at heyjay.com> wrote:

> > You can make a contract part of the TWS object (whatever that is)
> > using a has-a relationship.  In Finance::InteractiveBrokers::TWS, you
> > have a contract() method that returns the contract object. That then
> > allows you to do the method chaining that you want.
> I don't think I follow you here.  The main thing the user needs to do is ->new
> these objects.  Are you saying somehow return the class that can be new'd?
> If so will you show me a code example?

Basically, you use Finance::Interactive::TWS as a controller object.
It keeps track of everything and the user interacts with everything
through it. Behind the scenes you can have plug-ins, dispatchers,
delegates, or whatever you need to get the right objects to do the
right thing. Some CPAN modules handle this sort of thing for you, but
in general they are as much wrok as doing it yourself.

In your Finance::Interactive::TWS constructor, you set up everything.
Your object contains the contract object.

   sub new
      my( $class, @args ) = @_;

      my $self = {}; # or whatever;
      bless $self, $class;

      $self->{_contract} =
Finance::Interactive::TWS::blah::blah:blah->new( @args );


Then, to get the contract object, you have a simple accessor (how ever
you want to make that).

   sub contract { my $self = shift; return $self->{_contract} }

In your user script,

   use Finance::Interactive::TWS;

   my $money = Finance::Interactive::TWS->new( ... );

    # this gets the contract object and calls a method on it
   my $whatever = $money->contract->method_name();

brian d foy <brian.d.foy at gmail.com>

More information about the Chicago-talk mailing list