-
-
27 Aug 2008 02:17:14 UTC
- Distribution: Class-Data-ConfigHash
- Module version: 0.00002
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (1)
- Testers (4558 / 2 / 0)
- Kwalitee
Bus factor: 1- 39.83% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (18.58KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Daisuke Maki C<< >> - Stole the code from Catalyst and repackaged it
- Dependencies
- Class::Data::Inheritable
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Class::Data::ConfigHash - Add Catalyst-Style Config To Your Class
NAME
package MyClass; use base qw(Class::Data::ConfigHash); __PACKAGE__->config( foo => 'bar' );
DESCRIPTION
I often times find myself wanting a per-class config that can be used to provide sane class-level defaults, but with the ability to easily customize the values at run time.
package MyClass; __PACKAGE__->config({ foo => 1, bar => 2 }); # Later, in perhaps an initialize hook somewhere my %config = read_config_from_file() ; # say, %config = ( foo => 3 ) MyClass->config(\%config); MyClass->config->{foo}; # yields 3 MyClass->config->{bar}; # yields 2
The idea is that you can hardcode the defaults in your class, but you can also easily override them by merging the original hash with a newly given hash. This feature is handled beautifully in Catalyst.
So there, this module is basically that feature from Catalyst ripped out to a separate module so it can be used elsewhere.
To use, simply subclass it in your module:
package MyClass; use base qw(Class::Data::ConfigHash);
Done! Now you can use ->config in MyClass.
METHODS
config([\%hash])
Accessor for the underlying config.
# set $class->config(\%hash); $class->config->{whatever} = 'foo'; # get $class->config->{whatever};
If given a hashref argument, the values in the hashref are merged with whatever values that existed prior to that. This merge is performed recursively to the entire hash.
merge_config_hashes(\%lefthash, \%righthash)
Merges the two config hashes.
CREDITS
Sebastian Riedel, Marcus Ramberg, Matt S Trout wrote the code.
AUTHOR
Daisuke Maki
<daisuke@endeworks.jp>
- Stole the code from Catalyst and repackaged itLICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
Module Install Instructions
To install Class::Data::ConfigHash, copy and paste the appropriate command in to your terminal.
cpanm Class::Data::ConfigHash
perl -MCPAN -e shell install Class::Data::ConfigHash
For more information on module installation, please visit the detailed CPAN module installation guide.