The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::SymmetricAttribute - Symmetric Moose Attributes -- automatically update inverse attribute

VERSION

version 0.002

Synopsis

    package Foo;
    use Moose;

    has bar => (
        is => 'rw',
        isa => 'Bar',
    );

    with 'MooseX::SymmetricAttribute' => {
        attributes => {
            bar => 'foo'
        }
    };

    package Bar;
    use Moose;

    has foo => (
        is => 'rw',
        isa => 'Foo',
    );

    package main;
    my $bar = Bar->new;
    my $foo = Foo->new;

    $foo->bar( $bar );

    $bar->foo == $foo # true

Usage

Use this role to update both attributes in a symmetric relationship by setting one value.

To use it, compose the role into your class like this:

 with 'MooseX::SymmetricAttribute' => {
     attributes => {
         my_attribute_name_1 => foreign_attribute_name_1,
         my_attribute_name_2 => foreign_attribute_name_2,
     }
 };

If the foreign attribute is an ArrayRef or a Set::Object, the new value will be appended.

Warning

This is alpha quality software. There may be some bugs lingering in here, probably some race conditions too. Patches and tests are very welcome!

AUTHOR

  Gerhard Gossen

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Gerhard Gossen.

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