NAME

MooX::HandlesVia - NativeTrait-like behavior for Moo.

VERSION

version 0.001009

SYNOPSIS

{
  package Hashy;
  use Moo;
  use MooX::HandlesVia;

  has hash => (
    is => 'rw',
    handles_via => 'Hash',
    handles => {
      get_val => 'get',
      set_val => 'set',
      all_keys => 'keys'
    }
  );
}

my $h = Hashy->new(hash => { a => 1, b => 2});

$h->get_val('b'); # 2

$h->set_val('a', 'BAR'); # sets a to BAR

my @keys = $h->all_keys; # returns a, b

DESCRIPTION

MooX::HandlesVia is an extension of Moo's 'handles' attribute functionality. It provides a means of proxying functionality from an external class to the given atttribute. This is most commonly used as a way to emulate 'Native Trait' behavior that has become commonplace in Moose code, for which there was no Moo alternative.

SHORTCOMINGS

Due to current Moo implementation details there are some deficiencies in how MooX::HandlesVia in comparison to what you would expect from Moose native traits.

If these are issues for you, consider Sub::HandlesVia, which uses a different architecture, respecting triggers and coercions, and allowing read-write access to non-reference values. It should be possible to use Sub::HandlesVia as a drop-in replacement for MooX::HandlesVia.

PROVIDED INTERFACE/FUNCTIONS

The following handles_via keywords are reserved as shorthand for mapping to Data::Perl:

SEE ALSO

ORIGINAL AUTHOR

Matthew Phillips mattp@cpan.org

AUTHOR

Toby Inkster tobyink@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Matthew Phillips mattp@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.