in reply to Re^3: Exporter/@ISA confusion
in thread Exporter/@ISA confusion

Yes, if you want to export subroutines, you need to use Exporter. The most convenient way to do so is to use

use Exporter 'import';

... which does not need to modify @ISA at all, because all Exporter does is supply a subroutine named import.

But in most cases, object methods do not need to be exported at all. So neither new nor serve should be exported, because they will always be called on an object (or a class).

Replies are listed 'Best First'.
Re^5: Exporter/@ISA confusion
by qhen (Acolyte) on Jun 11, 2014 at 11:41 UTC

    ok, that's probably what I needed to hear.

    I just confirmed this with a test:

    package Test::Class; use strict; use warnings; sub new { my ($className, $config) = @_; my $self = {}; bless $self, $className; $self->{config} = \%{$config}; return $self; } sub doSomething { my ($self, $what) = @_; print $self->{config}->{$what} . "\n";; } 1;

    and the caller:

    #!/usr/bin/env perl use strict; use warnings; use lib '.'; use Test::Class; my $t = Test::Class->new( { name => 'bob', } ); $t->doSomething('name');

    ...no need for noisy Exporter/@ISA nonsense. Nice and clean.

    /me raises tankard!