++ed by:
AERO JROBINSON ROMANF CAMSPI EMAZEP

10 PAUSE users
15 non-PAUSE users.

Henry Van Styn

NAME

MooseX::ClassAttrSugar - Create add methods for merging defaults of HashRef attributes

SYNOPSIS

  package MyApp::Parent;
  
  use Moose;
  
  has 'foo_configs' => ( is => 'ro', builder => '_build_foo_configs', isa => 'HashRef' );
  sub _build_foo_configs { +{ 'base_setting1' => 'Some data' } }
  
  # then later ...
  package MyApp::Subclass;
  
  use Moose;
  extends 'MyApp::Parent';
  
  use MooseX::ClassAttrSugar;
  setup_apply_methods_for('foo_configs');
  apply_default_foo_configs(
    setting2  => 'Some other data',
    setting3  => 'Some more data'
  );
  
  
  # then later...
  
  my $obj = MyApp::Subclass->new;
  
  # $obj->foo_configs is initialized containing:
  # {
  #   base_setting1  => 'Some data',
  #   setting2       => 'Some other data',
  #   setting3       => 'Some more data'
  # }
  
  $obj->apply_foo_configs(
    setting4         => 'blah',
    setting5         => 'baz'
  );
  
  # $obj->foo_configs is now:
  # {
  #   base_setting1  => 'Some data',
  #   setting2       => 'Some other data',
  #   setting3       => 'Some more data',
  #   setting4       => 'blah',
  #   setting5       => 'baz'
  # }

TODO

Add support for other types, like ArrayRef Get flamed in #moose :)

AUTHOR

vs following mst's directions