The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Class::Data::Localize - Localizable, inheritable, overridable class data


  package Prince;
  use base qw(Class::Data::Localize);

  # Set up HomeDir as localizable, inheritable class data.

  # Declare the location of the home dir for this class.

  # Teporary move to
     { Prince->HomeDir('/stone/castle',my $move);
       if(Prince->kiss("princess")) {
          # live happy in stone castle until end of time

  print Prince->HomeDir; # back in /wooden/house when no kiss


This is an alternative to Class::Data::Inheritable with the feature added, that the class data can be localized, similar to the function of the keyword local.

Class Method mk_classdata

This class method works the same way as in C::D::I.

Since version 0.04 it is no longer a requirement to inherit from Class::Data::Localize, because mk_classdata is usable as a class function.

  package Mir;

  { my ($mkcd,$self) = (\&Class::Data::Localize::mk_classdata,__PACKAGE__);
    $mkcd->($self,'attribute1' => 9);


It is mostly compatible with C::D::I but attention should on the accessor parameter list. If an accessor is called with an array as argument list, than a move to this module will break your code.

   Stuff->DataFile(@args); # make sure @args <= 1 or
                           # unwanted things will happen

Localize Class Data

To localize a value give the accessor a lexical variable as second argument. Under the hood this module uses than the function of ReleaseAction to provide the feature. It stores in the variable an ReleaseAction object. This let's cancel the localization before the variable goes out of scope. When canceled the localized value becomes the new persistent value.




   * to cancel the localization is untested


Original code by Damian Conway.

Maintained by Michael G Schwern until September 2005.

Class::Data::Inheritable is maintained by Tony Bowden.

Derived Class::Data::Localize by Sebastian Knapp


Class::Data::Inheritable and Class::Data::Localize can't be used together easily. This was an early design decision which is maybe wrong.

Possible more.

Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


Copyleft 2007-2008 Sebastian Knapp <>

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