Class::Accessor::WithDefault - Set Default Value Implement on Class::Accessor
use Class::Accessor::WithDefault; __PACKAGE__->mk_accessors(qw/a b/,{c => 'default value'}); .... #..->new(); print $object->c; #default value
Class::Accessor is great, except for some inconvenience in setting the default value for the fields. Overrding the new method is some kind of inconvenient too.
This module allows you to set the default value for all the generated accessors by passing a hashref to the method.
NOTE: Don't use
$object->get("c");
to get the default value, this won't work.
Class::Accessor
Woosely.Xu
Copyright (C) 2009 by Woosley.Xu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install Class::Accessor::WithDefault, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Accessor::WithDefault
CPAN shell
perl -MCPAN -e shell install Class::Accessor::WithDefault
For more information on module installation, please visit the detailed CPAN module installation guide.