MooseX-OmniTrigger

 view release on metacpan or  search on metacpan

t/001-basic.t  view on Meta::CPAN


    has foo => (is => 'rw', isa => 'Exciting', coerce => 1,                          clearer => '_clear_foo', omnitrigger => \&_capture_changes);
    has bar => (is => 'rw', isa => 'Exciting', coerce => 1, default => 'DEFAULT'   ,                          omnitrigger => \&_capture_changes);
    has baz => (is => 'rw', isa => 'Exciting', coerce => 1, builder => '_build_bar',                          omnitrigger => \&_capture_changes);

    has blo => (is => 'ro', isa => 'Exciting', coerce => 1, default => 'DEFAULT', omnitrigger => \&_capture_changes);

    has goo => (is => 'rw', isa => 'Exciting', coerce => 1, default => 'DEFAULT'   , lazy => 1, clearer => '_clear_goo', omnitrigger => \&_capture_changes);
    has moo => (is => 'rw', isa => 'Exciting', coerce => 1, builder => '_build_bar', lazy => 1, clearer => '_clear_moo', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    has biz => (is => 'rw', isa => 'ArrayRef', weak_ref => 1,                                              omnitrigger => \&_capture_weaklings);
    has buz => (is => 'rw', isa => 'ArrayRef', weak_ref => 1, default => sub { $arrayref_buz }, lazy => 1, omnitrigger => \&_capture_weaklings);
    has bez => (is => 'rw', isa => 'ArrayRef', weak_ref => 1, default => sub { $arrayref_bez }, lazy => 1, omnitrigger => \&_capture_weaklings);

    has weaklings => (is => 'ro', isa => 'HashRef', default => sub { {} });

    has ziz => (is => 'rw', isa => 'Exciting', coerce => 1,

        initializer => sub {

            my ($self, $value, $set, $attr) = @_;

            $set->("$value-INITIALIZER");
        },

t/002-native.t  view on Meta::CPAN

        foo_string_inc     => 'inc'    ,
        foo_string_append  => 'append' ,
        foo_string_prepend => 'prepend',
        foo_string_replace => 'replace',
        foo_string_chop    => 'chop'   ,
        foo_string_chomp   => 'chomp'  ,
        foo_string_clear   => 'clear'  ,
        foo_string_substr  => 'substr' ,
    });

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    sub _capture_changes {

        my ($self, $attr_name, $new, $old) = (shift, @_);

        $self->changes->{$attr_name} = [

            @$old ? $old->[0] : 'NOVAL',
            @$new ? $new->[0] : 'NOVAL',
        ];

t/004-rebless.t  view on Meta::CPAN

    has goo => (is => 'rw', isa => 'Str',                   clearer => '_clear_goo', omnitrigger => sub { my $self = shift; $self->_capture_changes('moogoo', @_);                    });

    has pee => (is => 'rw', isa => 'Str', builder => '_build_pee', clearer => '_clear_pee', omnitrigger => sub { my $self = shift; $self->_capture_changes('peepoo', @_); $self->poo('POO'); });
    has poo => (is => 'rw', isa => 'Str',                          clearer => '_clear_poo', omnitrigger => sub { my $self = shift; $self->_capture_changes('peepoo', @_);                    });

    has biz => (is => 'rw', isa => 'Str', omnitrigger => sub { shift->_capture_changes('biz', @_) });
    has buz => (is => 'rw', isa => 'Str', omnitrigger => sub { shift->_capture_changes('buz', @_) });

    has ziz => (is => 'rw', isa => 'ArrayRef', omnitrigger => sub { ::is(ref($_[3][0]), 'ARRAY', 'old val is arrayref, in spite of auto_deref') if @{$_[3]} }, auto_deref => 1);

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    sub _capture_changes {

        my ($self, $attr_group, $attr_name, $new, $old) = (shift, @_);

        push(@{$self->changes->{$attr_group}}, sprintf('%s=>%s',

            @$old ? $old->[0] : 'NOVAL',
            @$new ? $new->[0] : 'NOVAL',
        ));

t/005-clone.t  view on Meta::CPAN

use strict; use warnings; use warnings (FATAL => qw(misc numeric uninitialized)); # use autodie;

use Test::Fatal;
use Test::More;

{ package MyClassA; use Moose; use MooseX::OmniTrigger;

    has foo => (is => 'rw', isa => 'Str', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    sub _capture_changes {

        my ($self, $attr_name, $new, $old) = (shift, @_);

        push(@{$self->changes->{$attr_name}}, sprintf('%s=>%s',

            @$old ? defined($old->[0]) ? $old->[0] : 'UNDEF' : 'NOVAL',
            @$new ? defined($new->[0]) ? $new->[0] : 'UNDEF' : 'NOVAL',
        ));

t/050-moosex-declare.t  view on Meta::CPAN


    plan skip_all => "MooseX::Declare isn't installed or wouldn't load" if $@;
}

class MyClass1 {

    use MooseX::OmniTrigger;

    has foo => (is => 'rw', isa => 'Str', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    method _capture_changes (Str $attr_name!, ArrayRef $new_val!, ArrayRef $old_val!) {

        push(@{$self->changes->{$attr_name}}, sprintf('%s=>%s',

            @$old_val ? defined($old_val->[0]) ? $old_val->[0] : 'UNDEF' : 'NOVAL',
            @$new_val ? defined($new_val->[0]) ? $new_val->[0] : 'UNDEF' : 'NOVAL',
        ));
    }
}

t/050-moosex-declare.t  view on Meta::CPAN

    is("@{$obj->changes->{foo} || []}", 'NOVAL=>INITVAL');
}


role MyRole1 {

    use MooseX::OmniTrigger;

    has foo => (is => 'rw', isa => 'Str', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'HashRef', default => sub { {} });

    method _capture_changes (Str $attr_name!, ArrayRef $new_val!, ArrayRef $old_val!) {

        push(@{$self->changes->{$attr_name}}, sprintf('%s=>%s',

            @$old_val ? defined($old_val->[0]) ? $old_val->[0] : 'UNDEF' : 'NOVAL',
            @$new_val ? defined($new_val->[0]) ? $new_val->[0] : 'UNDEF' : 'NOVAL',
        ));
    }
}

t/051-moosex-attribute-env.t  view on Meta::CPAN


    plan skip_all => "MooseX::Attribute::ENV isn't installed or wouldn't load" if $@;
}

local $ENV{foo} = 'FOO';

{ package MyClass; use Moose; use MooseX::Attribute::ENV; use MooseX::OmniTrigger;

    has foo => (traits => [qw(ENV)], is => 'rw', isa => 'Str', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'ArrayRef', default => sub { [] });

    sub _capture_changes {

        my ($self, $attr_name, $new, $old) = (shift, @_);

        push(@{$self->changes}, sprintf('%s:%s=>%s',

            $attr_name,

            @$old ? defined($old->[0]) ? $old->[0] : 'UNDEF' : 'NOVAL',

t/052-moosex-lazy_require.t  view on Meta::CPAN


    eval("use MooseX::LazyRequire");

    plan skip_all => "MooseX::LazyRequire isn't installed or wouldn't load" if $@;
}

{ package MyClass; use Moose; use MooseX::LazyRequire; use MooseX::OmniTrigger;

    has foo => (lazy_required => 1, is => 'rw', isa => 'Str', omnitrigger => \&_capture_changes);

    has changes => (is => 'ro', isa => 'ArrayRef', default => sub { [] });

    sub _capture_changes {

        my ($self, $attr_name, $new, $old) = (shift, @_);

        push(@{$self->changes}, sprintf('%s:%s=>%s',

            $attr_name,

            @$old ? defined($old->[0]) ? $old->[0] : 'UNDEF' : 'NOVAL',



( run in 0.699 second using v1.01-cache-2.11-cpan-5f2e87ce722 )