in reply to Re^2: OO manner of accessing static variables in a subclass?
in thread OO manner of accessing static variables in a subclass?

I'd like a way for the user to retrieve the versions

This can be done pretty simply. If we use the modules as kcott has written them, then a script could access Monks::Data and output its version like this:

use Monks::Data; print $Monks::Data::VERSION;

There's no real harm in adding a version() method to your module but neither is there any real benefit unless you are inheriting from a superclass and want an easy way for multiple levels of inherited classes all to report the same version, or at least refer to the parent/grandparent version somehow. I'm struggling to think of a use case like this; there probably is one somewhere but it would be a fairly rare occurrence.

Replies are listed 'Best First'.
Re^4: OO manner of accessing static variables in a subclass?
by HipDeep (Acolyte) on Aug 10, 2016 at 19:15 UTC

    Ok, thanks hippo! I thought the version method was needed to stick with the "always access data through a method" principle, but if it's not, that's fine too.

      You're not wanting the version of the object so you don't need a version method.

        There are class methods, too ("static" in Java parlance).

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,