A simple implementation to explain
gmargo's concept:
Foo.pm:
package Foo;
use strict;
use warnings;
sub new {
return bless {};
}
sub method {
return 1;
}
1;
script.pl:
#!/usr/bin/perl
use strict;
use warnings;
require Foo;
my $class = 'Foo';
my $obj = bless {}, $class;
print $obj->method;
Works fine, but if you remove the require Foo; line, you get the error Can't locate object method "method" via package "Foo" at script.pl line 9. perl needs the require statement to find and compile the source files.