Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages
Class::Data::ConfigHash(3) User Contributed Perl Documentation Class::Data::ConfigHash(3)

Class::Data::ConfigHash - Add Catalyst-Style Config To Your Class

  package MyClass;
  use base qw(Class::Data::ConfigHash);

    foo => 'bar'

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;
    foo => 1,
    bar => 2

  # Later, in perhaps an initialize hook somewhere
  my %config = read_config_from_file() ; # say, %config = ( foo => 3 )

  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.

Accessor for the underlying config.

  # set 
  $class->config->{whatever} = 'foo';

  # get

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.

Merges the two config hashes.

Sebastian Riedel, Marcus Ramberg, Matt S Trout wrote the code.

Daisuke Maki "<>" - Stole the code from Catalyst and repackaged it

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


2008-08-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.