Egg::Model::Cache::Base - Base class to succeed to from CACHE controller.


Egg-Model-Cache documentation Contained in the Egg-Model-Cache distribution.

Index


Code Index:

NAME

Top

Egg::Model::Cache::Base - Base class to succeed to from CACHE controller.

DESCRIPTION

Top

It is a base class to succeed to from the CACHE controller who generates it with Egg::Helper::Model::Cache.

METHODS

Top

This module operates as Wrapper of the module passed to 'setup_cache' method.

Therefore, the method that can be used in the module set by 'setup_cache' method is different.

setup_cache ([CACHE_MODULE])

It is set up to use CACHE_MODULE.

  __PACKAGE__->setup_cache('Cache::Memcached');

cache

It is a method of can use and when 'setup_cache' is done.

The object of the module passed by 'setup_cache' is returned.

SEE ALSO

Top

Egg::Release, Egg::Model, Egg::Model::Cache, Egg::Helper::Model::Cache, Egg::Component::Base,

AUTHOR

Top

Masatoshi Mizuno <lushe&64;cpan.org>

COPYRIGHT AND LICENSE

Top


Egg-Model-Cache documentation Contained in the Egg-Model-Cache distribution.

package Egg::Model::Cache::Base;
#
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
#
# $Id: Base.pm 293 2008-02-28 11:00:55Z lushe $
#
use strict;
use warnings;
use base qw/ Egg::Model Egg::Component::Base /;

our $VERSION= '0.01';

our $AUTOLOAD;

sub setup_cache {
	my $class= shift;
	$class->can('cache') and die q{'cache' method has already been setup.};
	my $pkg= shift || die q{I want cache module name.};
	$pkg->require or die __PACKAGE__. "- $@";
	no strict 'refs';  ## no critic.
	no warnings 'redefine';
	*{"${class}::cache"}= sub {
		$_[0]->{cache_context}
		   ||= $pkg->new( wantarray ? %{$_[0]->config}: $_[0]->config );
	  };
}
sub AUTOLOAD {
	my $self= shift;
	my($method)= $AUTOLOAD=~m{([^\:]+)$};
	$self->can('cache') || die q{'setup_cache' is not done.};
	no strict 'refs';  ## no critic.
	no warnings 'redefine';
	*{__PACKAGE__."::$method"}= sub {
		my $proto= shift;
		$proto->cache->$method(@_);
	  };
	$self->$method(@_);
}
sub DESTROY { }

1;

__END__