http://www.perlmonks.org?node_id=968104


in reply to Re: Wrong behavior of the implicit smart operator in the given/when blocks
in thread Wrong behavior of the implicit smart operator in the given/when blocks

Specifically, they think the interface is some combination of too confusing, too complex, too error prone. Smart::Match is seen as way better interface.

  • Comment on Re^2: Wrong behavior of the implicit smart operator in the given/when blocks

Replies are listed 'Best First'.
Re^3: Wrong behavior of the implicit smart operator in the given/when blocks
by tobyink (Canon) on Apr 30, 2012 at 16:40 UTC

    As I understand it, it's DOY's smartmatch which is the possible candidate for future Perls. This pushes the behaviour of smart match out to modules (on a lexically scoped basis). So you can:

    use smartmatch 'acme';

    And then the ~~ operator will start acting along the lines of whatever's defined in the smartmatch::engine::acme module. Perl will then come bundled with a backwards compatible behaviour (modelled on 5.14 most probably) and a simplified one.

    Personally, I tend to follow the rule of keeping the left hand side of the smart match as either a non-reference scalar or a blessed object. If you stick to that, then whatever you put on the right hand side, smart match generally behaves pretty sanely and intuitively. (With the possible exception of when you've got hashref on the right hand side - I'm not sure there's any completely intuitive behaviour in that case, but the current behaviour certainly seems no worse than anything else.)

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'