++ed by:
1 non-PAUSE user
Author image Tudor Marghidanu
and 1 contributors

NAME

MooseX::Role::UpdateAttributes - Update attribute values

SYNOPSIS

        package Models::Person {
                use Moose;

                with 'MooseX::Role::UpdateAttributes';

                has 'name' => (
                        is => 'ro',
                        isa => 'Str',
                        required => 1
                );

                has 'age' => (
                        is => 'rw',
                        isa => 'Int',
                        required => 1
                );

                __PACKAGE__->meta()->make_immutable();
        }

        package main {

                my $person = Models::Person->new(
                        {
                                name => 'Bruce Wayne',
                                age => 30
                        }
                );

                $person->set_attributes(
                        name => 'Wally West',
                        age => 22,
                        dummy => 100,
                );

                $person->name(); # Still 'Bruce Wayne' because the name attribute is read-only

                $person->age(); # Is now set to 22
        }

DESCRIPTION

This role allow for setting the values for setting values on multiple writable accesors at once.

METHODS

set_attributes

        $instance->set_attributes( %data );

AUTHOR

Tudor Marghidanu <tudor@marghidanu.com>

SEE ALSO

LICENSE

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.