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:

package Foo::Bar ; ..... our $VERSION = "0.00" ; .....
and somewhere you have:
my $obj = new Foo::Bar (...) ;
and somewhere else you want to find the $VERSION associated with $obj ?

Suppose you had Foo/Bar.pm:

package Foo::Bar ; use strict ; use warnings ; our $VERSION = "1.01" ; use base qw(Foo); sub new { return bless [], shift ; } ; 1 ;
and Foo.pm:
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 ;
Then:
use strict ; use warnings ; use Foo::Bar ; my $obj = new Foo::Bar ; print $obj->version(), "\n" ;
should print:
1.01
which may have been what you had in mind.

It may also be what kyle just recommended NOT to do ?


In reply to Re: Perl Inheritance & module variables by gone2015
in thread Perl Inheritance & module variables by diabelek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.