Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by tybalt89 (Prior)
on Aug 01, 2020 at 14:48 UTC ( #11120195=note: print w/replies, xml ) Need Help??


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 (Cardinal) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120195]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2020-10-20 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (210 votes). Check out past polls.

    Notices?