Home > Archive > PERL Beginners > March 2005 > Accessing the class
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Accessing the class
|
|
| Octavian Rasnita 2005-03-19, 3:56 pm |
| Hi all,
I know how to access a class from inside a subroutine, using "my $self =
shift;" then using that $self var, but how can I access the same class from
outside of any subroutine of a certain package?
I saw that I can put the following line in the package Package::Name,
outside of any subroutine:
my $class = Package::Name->new();
then I can use the var $class, but I don't know if it is the right way to
initialize the class from the same package.
And I don't like to use Package::Name directly because I might need to
change its name and then I would need to change that name in many places.
Thank you.
Teddy
| |
| Offer Kaye 2005-03-19, 8:55 pm |
| On Sat, 19 Mar 2005 13:37:17 +0200, Octavian Rasnita wrote:
>
> And I don't like to use Package::Name directly because I might need to
> change its name and then I would need to change that name in many places.
>
So place the package name in a variable, and use that variable in all
places. Then you have only 2 places to change - the actual package
declaration, and the variable declaration:
package Package::Name
use strict;
use warnings;
my $class = "Package::Name";
Hope this helps,
--
Offer Kaye
| |
| Randy W. Sims 2005-03-20, 8:55 pm |
| Offer Kaye wrote:
> On Sat, 19 Mar 2005 13:37:17 +0200, Octavian Rasnita wrote:
>
>
>
> So place the package name in a variable, and use that variable in all
> places. Then you have only 2 places to change - the actual package
> declaration, and the variable declaration:
>
> package Package::Name
> use strict;
> use warnings;
> my $class = "Package::Name";
Why not just use __PACKAGE__ ?
print "ok\n" if (my $class = "Package::Name") eq __PACKAGE__;
|
|
|
|
|