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

NAME

GX::Renderer - Renderer class

SYNOPSIS

    # Load the module
    use GX::Renderer;
    
    # Create a new renderer
    my $renderer = GX::Renderer->new;
    
    # Set the renderer's "xml"-format handler
    $renderer->handler(
        xml => GX::Callback::Method->new(
            invocant => $application->view( 'XML' ),
            method   => 'render'
        )
    );
    
    # Render
    $renderer->render( xml => ( context => $context, tidy => 1 ) );

DESCRIPTION

This module provides the GX::Renderer class which extends the GX::Class::Object class.

METHODS

Constructor

new

Returns a new GX::Renderer object.

    $renderer = GX::Renderer->new( %attributes );
Attributes:
  • handlers ( HASH reference )

    A reference to a hash with format / handler pairs. Handlers must be GX::Callback objects.

Returns:
Exceptions:

Public Methods

can_render

Returns true if the renderer can handle the specified format, otherwise false.

    $result = $renderer->can_render( $format );
Arguments:
  • $format ( string )

Returns:
  • $result ( bool )

clone

Clones the renderer.

    $clone = $renderer->clone;
Returns:

formats

Returns a list with the formats supported by the renderer.

    @formats = $renderer->formats;
Returns:
  • @formats ( strings )

handler

Returns / sets the handler for the specified format.

    $handler = $renderer->handler( $format );
    $handler = $renderer->handler( $format, $handler );
Arguments:
  • $format ( string )

  • $handler ( GX::Callback object | undef ) [ optional ]

Returns:
Exceptions:

handlers

Returns all format handlers.

    @handlers = $renderer->handlers;
Returns:

merge

Adds the format handlers from the given renderers.

    $renderer->merge( @renderers );
Arguments:
Exceptions:

Already existing handlers are replaced.

render

Executes the specified format handler.

    $renderer->render( $format, @arguments );
Arguments:
  • $format ( string )

  • @arguments ( scalars )

Exceptions:

Exceptions raised in the handler are caught and rethrown. If render() is called in void context, an exception is raised if the specified format is not supported by the renderer. In non-void context, render() returns false if the specified format is not supported, otherwise true.

    $result = $renderer->render( $format, @arguments );
Arguments:
  • $format ( string )

  • @arguments ( scalars )

Returns:
  • $result ( bool )

Exceptions:

USAGE

Fallback Handler

If set, the "*" format handler acts as a fallback.

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright (c) 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.