http://qs321.pair.com?node_id=11120195


in reply to Re^2: Use cases for 'sub Pckg::func { }' ?
in thread Use cases for 'sub Pckg::func { }' ?

I'm using the "block" eval, which is just a "try/catch" mechanism, so I can "die" deep in parsing recursion and still be able to go on to the next test case. It's just a different feature with the same name as the "string" eval, which is what they don't want to allow.

I could have used a hash to map operations to their proper subs, but why bother when perl already has a hash that does that for me. "Polymorphism forever!" hehehe

"Ah, I think I got it," - yes, yes you do :)

  • Comment on Re^3: Use cases for 'sub Pckg::func { }' ?

Replies are listed 'Best First'.
Re^4: Use cases for 'sub Pckg::func { }' ?
by LanX (Saint) on Aug 03, 2020 at 13:54 UTC
    Thanks.

    I can see two/three use patters now

    • your demo: ad hoc definition of small but related OOP classes in a horizontal way (contrary to "vertical" inheritance)
    • keeping the class' namespace clean of imported subs (kind of namespace::clean but right from the beginning)
    the latter even
    • on a method basis
    • without need of explicit import
    { package Subs::I::Want; sub Target::Class::method { my ($self) = shift; $self->method2(); sub_I_want() } } { package Other::Subs::I::Want; sub Target::Class::method2 { other_sub_I_want() } }

    hence

    • Target::Class->method() or ->method2() work
    • Target::Class->sub_i_want() or ->other_sub_I_want() won't work
    GREAT, learned something new! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery