Class::MethodCache - Manipulate Perl's method resolution cache


Class-MethodCache documentation Contained in the Class-MethodCache distribution.

Index


Code Index:

NAME

Top

Class::MethodCache - Manipulate Perl's method resolution cache

SYNOPSIS

Top

	use Class::MethodCache;

DESCRIPTION

Top

EXPORTS

Top

High level API

set_cached_method $glob, $coderef

Sets the CV slot of the glob to $coderef, and sets the cvgen slot of the glob to signify that this is a currently valid cache entry.

Overwriting a real method is an error. Use set_cvgen with get_class_gen first to force this.

Adding a cache entry to a shared GV (get_gv_refcount > 1) is an error, too, because the GV is shared by more than one stash and this will cause strange behavior. Use set_cv and set_cvgen for that. Devel::Peek will probably tell you wtf is going on.

get_cached_method $glob

Gets the CV slot of the glob if this is a currently valid cache entry.

update_cvgen $glob

Updates the cvgen slot to mark this cache entry as valid.

It is an error to update cvgen if it is not set but the CV slot is set, because that will overwrite a real method.

To force this behavior call set_cvgen with get_class_gen.

delete_cv $glob

Remove the CV and reset the CVGEN of a glob.

Low level API

get_class_gen $class

Returns the current class generation for a class.

This is like get_pkg_gen in mro (See also MRO::Compat).

This is equal to PL_sub_generation under perls predating mro, but still requires $class to be passed in for consistency.

This is provided mainly for convenience, for furthere manipuatlion of method caching please consult MRO::Compat, it has all the encessary functionality for manipulating cache invalidation. Using it in conjunction with Class::C3::XS is reccomended on perls below 5.9.5.

get_cv $glob

This differs from *{$glob}{CODE} in that it will return the cached code ref if any, wheras accessing the code slot is more like GvCVu(gv) (which checks that GvCVGEN is == 0 first).

set_cv $glob, $coderef

Manipulate GvCV directly.

A value of undef will clear the field.

get_cvgen $glob

Returns the cvgen slot of the gv.

set_cvgen $glob, $uint

Manipulate GvCVGEN directly.

Any value greater than zero implies the GvCV is a cache entry. If GvCV is not set then this is a cache of a failed lookup.

SEE ALSO

Top

mro, MRO::Compat, Class::C3::XS

VERSION CONTROL

Top

This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.

AUTHOR

Top

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Top


Class-MethodCache documentation Contained in the Class-MethodCache distribution.

#!/usr/bin/perl

package Class::MethodCache;

use strict;
use warnings;

use vars qw($VERSION @ISA);

BEGIN {
	$VERSION = '0.05';

	local $@;

	eval {
		require XSLoader;
		__PACKAGE__->XSLoader::load($VERSION);
		1;
	} or do {
		warn $@;
		require DynaLoader;
		push @ISA, 'DynaLoader';
		__PACKAGE__->bootstrap($VERSION);
	};

}

use Sub::Exporter -setup => {
	exports => [qw(
		get_gv_refcount
		set_cvgen
		get_cvgen
		set_cv
		get_cv
		get_class_gen

		delete_cv
		update_cvgen
		set_cached_method
		get_cached_method
	)],
	groups => {
		default => [qw(
			update_cvgen
			set_cached_method
			get_cached_method
		)],
	},
};



__PACKAGE__

__END__