[Chicago-talk] Shortening a module name

Jay Strauss me at heyjay.com
Mon Feb 20 09:46:27 PST 2006


Hi,

I have a module:

Finance::InteractiveBrokers::TWS::com::ib::client::Contract

When a user creates a:

my $tws = Finance::InteractiveBrokers::TWS->new();

is there a way I could provide a shortcut, in 
Finance::InteractiveBrokers::TWS, for the user to create a contract, without 
having to build a sub like

sub new_Contract {
    my $self = shift;
    return 
Finance::InteractiveBrokers::TWS::com::ib::client::Contract->new(@_);
}

within Finance::InteractiveBrokers::TWS?

I was thinking something along the lines of:

my $contract = $tws->contract->new();

Maybe by employing AUTOLOAD, or some other means?  I've been messing with 
AUTOLOAD but I can't get it to work.  The above obviously wants the 
$tws->contract to return an object, that can be new'd, whereas I'd like to 
get "new" as a parameter to AUTOLOAD and I could do logic for the proper 
dispatch.

I know I could do $tws->contract('new'), but that doesn't seem OO proper.

Thanks
Jay


More information about the Chicago-talk mailing list