Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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]
[Lady_Aleena]: james28909, did you even look at the subs?
[james28909]: yes
[Lady_Aleena]: And you see how the first two are vastly different than the third, right?
[james28909]: it would be to much work just to get around renaming three subs lol
[james28909]: but you could put it all in one sub and return the same data type that was inputted. i could write a small example maybe

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-05-24 05:04 GMT
Find Nodes?
    Voting Booth?