in reply to Re^2: OOP - Constant Vs. Subroutine
in thread OOP - Constant Vs. Subroutine

How would you do that? Would you have to call it like a method?
Class->constant;
That would prevent the in-lining behavior, but I guess it's no worse than a normally defined simple method.

Replies are listed 'Best First'.
Re^4: OOP - Constant Vs. Subroutine
by Anonymous Monk on May 12, 2007 at 17:02 UTC

    Not really, Class->constant won't inherit from Superclass->constant ; it needs to be defined in both.

    however $classObject->constant will inherit constants from superclass as class object methods , and allow the ability to override

    so...

    package aaa; use constant HELLO=> 'world'; use constant PUNCTUATION=> '!'; sub new { #std constructor here } package bbb; our @ISA= qw( aaa ); use constant HELLO=> 'universe'; package main; my $a= aaa->new(); my $b= bbb->new(); print "\n Hello " . $a->HELLO . $a->PUNCTUATION ; print "\n Hello " . $b->HELLO . $b->PUNCTUATION ;

    will get you

    Hello world! Hello universe!

    but bbb->PUNCTUATION doesn't exist

      but bbb->PUNCT­UATION doesn't exist

      Did you try it?

      package aaa; use constant HELLO=> 'world'; use constant PUNCTUATION=> '!'; package bbb; our @ISA= qw( aaa ); use constant HELLO=> 'universe'; package main; print "\n Hello ", aaa->HELLO(), aaa->PUNCTUATION(); print "\n Hello ", bbb->HELLO(), bbb->PUNCTUATION();

      produces:

      Hello world! Hello universe!

      - tye        

        I had a typo in my ISA when I tried it ( i used isa aaaa ), giving me an inheritance error. You are most certainly correct.