in reply to Using constants as methods

Not coding much OOP myself, but it depends what you want.

This constant won't be available from other files, especially it won't be inherited, but the getter method would.

So shall it be private or not?

edit

Oh! Sorry I misread constant as Readonly , never mind.

I don't think that use constant is a good idea because it does the same but in an obfuscated way.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Using constants as methods
by vsespb (Chaplain) on Mar 13, 2016 at 01:50 UTC
    This constant won't be available from other files, especially it won't be inherited, but the getter method would.
    No! It works fine (when we talk about method)! Seems it's available from any other place, and can be inherited. Example:
    package XX; use constant timeout => 42; 1; package YY; use parent -norequire, 'XX'; 1; package main; use strict; use warnings; my $y = bless +{}, "YY"; print $y->timeout; # fine! 1;
    So shall it be private or not?
    Not necessary.
      Yeah I noticed already in the meantime, please see update.

      Sorry its late here... :)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!