in reply to Re: Multiple classes in modules
in thread Multiple classes in modules

That's indeed true. I didn't know that, but tried the following, it works:
# file: MyDir/MyTest.pm package MyDir::Foo; sub new{ my $class = shift; my $self = {}; bless $self, $class; return $self; } sub foo{ print "Foo\n"; } package MyDir::Bar; sub new{ my $class = shift; my $self = {}; bless $self, $class; return $self; } sub bar{ print "Bar\n"; } 1;
With test code:
use strict; use MyDir::MyTest; my $foo = MyDir::Foo->new(); $foo->foo(); my $bar = MyDir::Bar->new(); $bar->bar();
Updated. In fact, one can simply name the package as "Foo" and "Bar" instead of "MyDir::Foo" and "MyDir::Bar". In other words, "use" is tied to the directory layout, but not to the contents of the files. Am I too general here?

Replies are listed 'Best First'.
Re^3: Multiple classes in modules
by ikegami (Patriarch) on Oct 05, 2004 at 20:16 UTC

    The catch is that use MyDir::MyTest; will attempt to call MyDir::MyTest::import. That can be avoided by using either
    use MyDir::MyTest ();
    or
    BEGIN { require MyDir::MyTest; }
    or
    BEGIN { require "MyDir/MyTest.pm"; }