in reply to Re^3: Abstract Factory
in thread Abstract Factory

#!/bin/perl package first; use strict; use warnings; sub new{ my $class = shift; my $type = shift; return bless \$type, $class; } sub greet { my $type = shift; print "\n hello got something .. $$type \n"; } 1; package AFactory; use strict; use warnings; sub get_new { my $class = shift; my $type = shift; return $class->new(@_); } 1; my $greeter = AFactory->get_new("first","dow dow"); $greeter->greet(); print "hellow\n";
!!!error is : Can't locate object method "new" via package "AFactory" at new.pl line 31.

Replies are listed 'Best First'.
Re^6: Abstract Factory
by Happy-the-monk (Canon) on Oct 06, 2005 at 19:22 UTC

    Can't locate object method "new" via package "AFactory" at new.pl line 31.

    That's because package "AFactory" hasn't got any method called "new". See?

    Did you think it should get it from a parent class, the one called "first" maybe?
    Then you need to specify that using either use base 'first'; or push @ISA, 'first';.

    Cheers, Sören