The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::Data::Reloadable - inheritable, overridable class data that survive reloads

SYNOPSIS

    package Stuff;
    use base qw(Class::Data::Reloadable);

    # Set up DataFile as inheritable class data.
    Stuff->mk_classdata('DataFile');

    # Declare the location of the data file for this class.
    Stuff->DataFile('/etc/stuff/data');

    # ... reload Stuff within same interpreter

    print Stuff->DataFile;   # /etc/stuff/data

DESCRIPTION

A drop-in replacement for Class::Data::Inheritable, but subclasses can be reloaded without losing their class data. This is useful in mod_perl development, and may be useful elsewhere.

In mod_perl, Apache::Reload conveniently reloads modules that have been modified, rather than having to restart Apache. This works well unless the module stores class data that are not re-created during the reload. In this situation, you still need to restart the server, in order to rebuild the class data.

Saves many (if your code starts out buggy like mine) Apache restarts.

But only if you're strict about storing all class data using this mechanism.

See Class::Data::Inheritable for more examples.

Drop-in

If you want to switch over to this module in a large app, instead of changing all references to Class::Data::Inheritable, you can instead create an empty subclass Class::Data::Inheritable and put it somewhere in your Perl search path that gets searched before the path with the real Class::Data::Inheritable, e.g.

    use lib '/my/lib';

and /my/lib/Class/Data/Inheritable.pm is:

    package Class::Data::Inheritable;
    use base 'Class::Data::Reloadable';
    1;

METHODS

mk_classdata

Creates a classdata slot, optionally setting a value into it.

    $client->mk_classdata( 'foo' );
    $client->classdata->foo( 'bar' );
    # same thing:
    $client->mk_classdata( foo => 'bar' );

Note that during a reload, this method may be called again for an existing attribute. If so, any value passed with the method is silently ignored, in favour of whatever value was in the slot before the reload.

This also provides a _foo_accessor alias.

AUTOLOAD

If the class has been reloaded, and if before the reload, other classes have called mk_classdata on this class, then some accessors will be missing after the reload. AUTOLOAD replaces these methods the first time they are called.

Redispatches (via NEXT) to any AUTOLOAD method further up the chain if no attribute is found.

AUTHOR

David Baird, <cpan@riverside-cms.co.uk>

BUGS

Please report any bugs or feature requests to bug-class-data-separated@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

DEBUGGING

Set $Class::Data::Reloadable::DEBUG = 1 to get debugging output (via warn) that may be useful for debugging either this module, or classes that inherit from it.

You may also want to dig around in $Class::Data::Reloadable::ClassData, but don't tell anyone I told you.

COPYRIGHT & LICENSE

Copyright 2004 David Baird, All Rights Reserved.

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