Re: Trigger before/around/after stuff

[email protected] (Sartak)
Newsgroups perl.moose
Message-ID <[email protected]>
On Tue, Jul 22, 2008 at 10:18 AM, Paul Driver <[email protected]> wrote:
> I think the major benefit of the "around" trigger was being able to filter
> the value going into the setter.  I don't have any use case for 'before'
> that couldn't be accomplished with older "standard" (after) triggers - so
> some kind of setter-filter (needs a better name) would probably do just as
> well.  That could be done by a MooseX, potentially.

Anything that depends on the old value would be a use case for
"before". For example, one of my uses would be:

has type => (
    trigger => {
        before => sub {
            $registry->unregister_tile_by_type($_[0], $_[1]);
        },
        after => sub {
            $registry->register_tile_by_type($_[0], $_[1]);
        },
    },
);

before is also useful for additional validation. You want to throw the
exception *before* you set an invalid value.

Shawn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.