in reply to Perl Inheritance & module variables
So, you have a module called Foo::Bar and objects of the class Foo::Bar, and you want to find the version of the module associated with the object, yes ? For example, while doing some superclass stuff ?
Which would be something along the lines:
and somewhere you have:package Foo::Bar ; ..... our $VERSION = "0.00" ; .....
and somewhere else you want to find the $VERSION associated with $obj ?my $obj = new Foo::Bar (...) ;
Suppose you had Foo/Bar.pm:
and Foo.pm:package Foo::Bar ; use strict ; use warnings ; our $VERSION = "1.01" ; use base qw(Foo); sub new { return bless [], shift ; } ; 1 ;
Then:package Foo ; use strict ; use warnings ; our $VERSION = "0.11" ; sub version { my ($self) = @_ ; no strict 'refs' ; # NB: seatbelt off. return ${ref($self)."::VERSION"} ; # "Symbolic Reference" } ; 1 ;
should print:use strict ; use warnings ; use Foo::Bar ; my $obj = new Foo::Bar ; print $obj->version(), "\n" ;
which may have been what you had in mind.1.01
It may also be what kyle just recommended NOT to do ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Inheritance & module variables
by diabelek (Beadle) on Sep 19, 2008 at 16:26 UTC | |
by gone2015 (Deacon) on Sep 20, 2008 at 08:53 UTC |