in reply to howto reference to a external sub/object/constructor thingy

The Temp:: is a trap - Temp.pm would need to reside in a folder called Temp dangling off the @INC path somewhere.

Code that works and looks somewhat like that which you posted is:

#!/usr/bin/perl use strict; package Tool; sub new{ print "test"; } 1; package main; my $page = 'module'; my $obj; my %states = ( module => sub {Tool->new ()}, ); if ($states{$page}){ $obj = $states{$page}->(); }

Prints:

test

Update per chromatic's suggestion


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: howto reference to a external sub/object/constructor thingy
by chromatic (Archbishop) on Feb 23, 2006 at 04:37 UTC

    That breaks inheritance. You oughtn't assume anything about how Tool gets or implements new(). I suggest instead:

    my %states = ( module => sub { Tool->new( @_ ) }, );