Any-Renderer

 view release on metacpan or  search on metacpan

lib/Any/Renderer.pm  view on Meta::CPAN

=head1 GLOBAL VARIABLES

=over 4

=item @Any::Renderer::LowPriProviders

A list of backend providers which have lower precedence (if there is more than one module which provides a given format).
The earlier things appear in this list, the lower the precedence.

Defaults to C<Data::Serializer> as this provides both XML::Simple and Data::Dumper (which have native Any::Renderer backends).

=back

=head1 WRITING A CUSTOM BACKEND

Back-end modules should have the same public interface as Any::Renderer itself:

=over 4

=item $o = new Any::Renderer::MyBackend($format, \%options);

=item $string = $o->render($data_structure);

=item $bool = requires_template($format)

=item $arrayref = available_formats()

=back

For example:

	package Any::Renderer::MyFormat;
	sub new {
	  my ( $class, $format, $options ) = @_;
	  die("Invalid format $format") unless($format eq 'MyFormat');
	  return bless({}, $class); #More complex classes might stash away options and format 
	}
	
	sub render {
	  my ( $self, $data ) = @_;
	  return _my_format($data);
	}
	
	sub requires_template {
	  die("Invalid format") unless($_[0] eq 'MyFormat');
	  return 0; #No template required
	}
	
	sub handle_formats {
	  return [ 'MyFormat' ]; #Just the one
	}

=head1 SEE ALSO

=over 4

=item All the modules in the Any::Renderer:: distribution

L<http://search.cpan.org/dist/Any-Renderer>.
Each module lists the formats it supports in the FORMATS section.
Many of also include sample output fragments.

=item L<Any::Template>

A templating engine is a special case of a renderer (one that uses a template, usually from a file or string, to control formatting).
If you are considering exposing another templating language via Any::Renderer, instead consider exposing it via Any::Template.
All the templating engines supported by Any::Template are automatically available via Any::Renderer.

=item L<Data::Serializer>

A serializer is a special case of a renderer which offers bidirectional processing (rendering == serialization, deserialisation does not map to the renderer interface).
If you are considering exposing another serialization mechanism via Any::Renderer, instead consider exposing it via Data::Serializer.
All the serializers supported by Data::Serializer are automatically available via Any::Renderer.

=back
	
=head1 VERSION

$Revision: 1.14 $ on $Date: 2006/09/04 12:15:52 $ by $Author: johna $

=head1 AUTHOR

Matt Wilson (original version by John Alden) <cpan _at_ bbc _dot_ co _dot_ uk>

=head1 COPYRIGHT

(c) BBC 2006. This program is free software; you can redistribute it and/or modify it under the GNU GPL.

See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt

=cut



( run in 1.287 second using v1.01-cache-2.11-cpan-b16cb0d3907 )