in reply to Re: How to create nested class in perl?
in thread How to create nested class in perl?
Incorrect. Any external code which does a use Frobnicate will get access to all packages/classes within Frobnicate.pm. The relationship of "file name == package name" is purely a matter of convention. It is not enforced in any way by perl.
Let's create a module Foo.pm containing:
and then write a program that says:package Bar; sub identify { print "I'm in package " . __PACKAGE__ . "\n"; } 1;
Running this program produces the output#!/usr/bin/perl use Foo; Bar->identify(); Foo->identify();
As you can see, Bar being named differently than the file it's in does not in any way reduce its visibility or accessibility to the outside world.I'm in package Bar Can't locate object method "identify" via package "Foo" (perhaps you f +orgot to load "Foo"?) at...
But don't do that in production code, of course. The reason for the convention is because use Foo giving you access to package Bar is confusing as hell, especially if it doesn't give access to package Foo.
|
|---|