Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Smartmatch alternatives

by tobyink (Abbot)
on Dec 17, 2013 at 19:22 UTC ( #1067514=note: print w/ replies, xml ) Need Help??


in reply to Re: Smartmatch alternatives
in thread Smartmatch alternatives

I agree with:

"My problem with smartmatch is that it tries to replace several more explicit constructs. I prefer to just use the more explicit one, leaving less to heuristics."

... in most cases. Don't use ~~ when ==, eq or =~ would do a better job.

However, there is one place I really miss smartmatch. Let's take for example RDF::RDB2RDF; you don't need to know all the details of what it does; suffice to say that it's got user-configurable objects which process a database. One of the options that can be configured is which tables (if any) should be skipped. I liked being able to say "set the ignore_tables option to anything that can be used as the right hand side of a smart match".

So if they wanted to skip one particular table, they could do ignore_tables => "foo", if they had a list of tables to skip, then ignore_tables => \@private, or they could use a regexp ignore_tables => qr{^priv}, or if they had more complex requirements, ignore_tables => sub {...}.

Smartmatch made implementing that really easy. And it's that aspect of smart match that made me want to write a stable replacement for it.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^2: Smartmatch alternatives
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-30 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls