Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067514]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-04-23 04:09 GMT
Find Nodes?
    Voting Booth?