Andrew Sterling Hanenkamp > Contentment-0.011_033 > Contentment::Setting



Annotate this POD

Module Version: 0.12   Source  


Contentment::Setting - A Contentment plugin for storing configuration


This module is required by the Contentment core and is used to store settings and configuration information in the database.


This class adds the following methods to the context:

$settings = $context->settings

Returns a reference to a hash containing all the settings. Settings are permanently saved to the database when changed.

This hash can be used to store most complex types. It uses YAML to encode all the values, which can encode just about anything.

However, there are a few caveats to be careful about:

  • References to blessed items or types other than scalars, hashes, or arrays might not store and load again quite as you expect. In particular, objects can be blessed into classes that aren't even loaded.
  • Be careful modifying deep parts of the code without explicitly notifying the settings object. For example:
      my $settings = $context->settings;
      my %hash = ( foo => 1, bar => 2 );
      # Works great!
      $settings->{blah} = \%hash;
      $hash{baz} = 3;
      # Bad stuff! Outputs: foo, bar
      # $settings doesn't know about baz!
      print(join(', ', keys %$settings),"\n");
      # Make sure you always notify the hash of deep changes:
      $settings->{blah} = \%hash;


Andrew Sterling Hanenkamp, <>


Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved.

Contentment is distributed and licensed under the same terms as Perl itself.

syntax highlighting: