SYNOPSIS

  package My::Adapter;

  use strict;
  use Class::Adapter::Builder
      ISA     => 'Specific::API',
      METHODS => [ qw{foo bar baz} ],
      method  => 'different_method';

  1;

DESCRIPTION

\*(C`Class::Adapter::Builder\*(C' is another mechanism for letting you create Adapter classes of your own.

It is intended to act as a toolkit for generating the guts of many varied and different types of Adapter classes.

For a simple base class you can inherit from and change a specific method, see Class::Adapter::Clear.

The Pragma Interface

The most common method for defining Adapter classes, as shown in the synopsis, is the pragma interface.

This consists of a set of key/value pairs provided when you load the module.

# The format for building Adapter classes use Class::Adapter::Builder PARAM => VALUE, ...

\s-1ISA\s0

The \*(C`ISA\*(C' param is provided as either a single value, or a reference to an \*(C`ARRAY\*(C' containing is list of classes. Normally this is just a straight list of classes. However, if the value for \*(C`ISA\*(C' is set to '_OBJECT_' the object will identify itself as whatever is contained in it when the \*(C`->isa\*(C' and \*(C`->can\*(C' method are called on it.

\s-1NEW\s0

Normally, you need to create your \*(C`Class::Adapter\*(C' objects separately: # Create the object my $query = CGI->new( 'param1', 'param2' );

# Create the Decorator my $object = My::Adapter->new( $query ); If you provide a class name as the \*(C`NEW\*(C' param, the Decorator will do this for you, passing on any constructor arguments. # Assume we provided the following # NEW => 'CGI',

# We can now do the above in one step my $object = My::Adapter->new( 'param1', 'param2' );

\s-1AUTOLOAD\s0

By default, a \*(C`Class::Adapter\*(C' does not pass on any methods, with the methods to be passed on specified explicitly with the 'METHODS' param. By setting \*(C`AUTOLOAD\*(C' to true, the \*(C`Adapter\*(C' will be given the standard \*(C`AUTOLOAD\*(C' function to to pass through all unspecified methods to the parent object. By default the \s-1AUTOLOAD\s0 will pass through any and all calls, including calls to private methods. If the \s-1AUTOLOAD\s0 is specifically set to '\s-1PUBLIC\s0', the \s-1AUTOLOAD\s0 setting will \s-1ONLY\s0 apply to public methods, and any private methods will not be passed through.

\s-1METHODS\s0

The \*(C`METHODS\*(C' param is provided as a reference to an array of all the methods that are to be passed through to the parent object as is.

Any params other than the ones specified above are taken as translated methods.

# If you provide the following # foo => bar

# It the following are equivalent $decorator->foo; $decorator->_OBJECT_->bar;

This capability is provided primarily because in Perl one of the main situations in which you hit the limits of Perl's inheritance model is when your class needs to inherit from multiple different classes that containing clashing methods.

For example:

# If your class is like this package Foo;

use base 'This', 'That';

1;

If both \*(C`This->method\*(C' exists and \*(C`That->method\*(C' exists, and both mean different things, then \*(C`Foo->method\*(C' becomes ambiguous.

A \*(C`Class::Adapter\*(C' could be used to wrap your \*(C`Foo\*(C' object, with the \*(C`Class::Adapter\*(C' becoming the \*(C`That\*(C' sub-class, and passing \*(C`$decorator->method\*(C' through to \*(C`$object->that_method\*(C'.

METHODS

Yes, \*(C`Class::Adapter::Builder\*(C' has public methods and later on you will be able to access them directly, but for now they are remaining undocumented, so that I can shuffle things around for another few versions.

Just stick to the pragma interface for now.

SUPPORT

Bugs should be reported via the \s-1CPAN\s0 bug tracker at

<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Adapter>

For other issues, contact the author.

AUTHOR

Adam Kennedy <[email protected]>

RELATED TO Class::Adapter::Builder…

Class::Adapter, Class::Adapter::Clear

COPYRIGHT

Copyright 2005 - 2010 Adam Kennedy.

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

The full text of the license can be found in the \s-1LICENSE\s0 file included with this module.