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

Didn't the requirement from Rosetta forbid the use of eval ?

I'm a bit puzzled why you need all those packages, instead of defining separate methods in the same namespace.

Tho I'm often not "skilled" enough to understand your code... ;-)

++ for creativity! =)

update

Ah, I think I got it, those packages are classes and you populate them with methods in a shorter syntax.

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

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

Replies are listed 'Best First'.
Re^3: Use cases for 'sub Pckg::func { }' ?
by tybalt89 (Monsignor) on Aug 01, 2020 at 14:48 UTC

    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 :)

      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