CGI::Application::Plugin::YAML - YAML methods for CGI::App


CGI-Application-Plugin-YAML documentation Contained in the CGI-Application-Plugin-YAML distribution.

Index


Code Index:

NAME

Top

CGI::Application::Plugin::YAML - YAML methods for CGI::App

SYNOPSIS

Top

Just a little wrapper. Useful to add YAML methods to you CGI::App object. The whole YAML module is lazy loaded, so all that gets loaded at first is this little wrapper.

    use CGI::Application::Plugin::YAML qw( :std );

Load YAML:-

    $self->YAML->Load( $yamldata );

Dump YAML:-

    $self->YAML->Dump( $perldata );

The methods LoadFile and DumpFile can also be imported. You need to specify :max on your use.

    use CGI::Application::Plugin::YAML qw( :all );

Load YAML file:-

    $self->YAML->LoadFile( $yamldata );

Dump YAML file:-

    $self->YAML->DumpFile( $perldata );

DESCRIPTION

Top

This module is a wrapper around YAML::Any. It uses YAML::Any so looks for the best YAML module your system has to offer. There are Pure Perl YAML modules (such as YAML::Old) that you can easily package with your app. If like me you didn't like the idea of having functions called Dump and Load imported to your namespace, then I'd use this wapper.

Methods

Top

YAML

This is the object that gets exported. See SYNOPSIS

Export groups

Top

Only an object called YAML is exported. The export groups allow you to choose what methods that object contains.

:all exports:-

    Dump Load DumpFile LoadFile

:std exports:-

    Dump Load

FAQ

Top

Why?

Having Dump and Load as functions are far to ambiguous for my liking. This also making inheritance on the YAML methods a lot easier.

Thanks to:-

Top

YAML

Come join the bestest Perl group in the World!

Top

Bristol and Bath Perl moungers is renowned for being the friendliest Perl group in the world. You don't have to be from the UK to join, everyone is welcome on the list:- http://perl.bristolbath.org

AUTHOR

Top

Lyle Hopkins ;)


CGI-Application-Plugin-YAML documentation Contained in the CGI-Application-Plugin-YAML distribution.

package CGI::Application::Plugin::YAML;




use strict;
use warnings;
use Carp;

use vars qw ( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS $IMPORTGROUP );

require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = ( 'YAML' );

%EXPORT_TAGS = (
    all => [ 'YAML' ],
    std => [ 'YAML' ],
);

$VERSION = '0.03';

#$IMPORTGROUP = ':std';

my $yaml;

sub import {
#    local( $IMPORTGROUP );
#    $IMPORTGROUP = $_[1];
    $yaml = new CGI::Application::Plugin::YAML::guts( $_[1] );
    CGI::Application::Plugin::YAML->export_to_level(1, @_);
}#sub

sub YAML {
    unless ( $yaml->{params}->{__loaded} ) {
        $yaml->__LoadYAML();
    }#unless
    return $yaml;
}#sub


package CGI::Application::Plugin::YAML::guts;

sub new {
    my $class = shift;
#    require YAML::Any;
    my $obj = {
        params => {
            group => shift,
        },
    };
    $obj->{params}->{group} = ':std' unless $obj->{params}->{group};
    
#    if ( $CGI::Application::Plugin::YAML::IMPORTGROUP eq ':all' ) {
    if ( $obj->{params}->{group} eq ':all' ) {
#        YAML->import( qw( Dump Load DumpFile LoadFile ) );
        ### Overloading imported routines as class causes problems when called
        sub LoadFile {
            shift; ### get rid of class
            YAML::Any::LoadFile( @_ );
        }#sub
        sub DumpFile {
            shift;
            YAML::Any::DumpFile( @_ );
        }#sub
    }#if
    else {
        YAML->import( qw( Dump Load ) );
    }#else
    sub Load {
        shift;
        YAML::Any::Load( @_ );
    }#sub
    sub Dump {
        shift;
        YAML::Any::Dump( @_ );
    }#sub
    bless( $obj, $class );
    return $obj;
}#sub


sub __LoadYAML {
    require YAML::Any;
    YAML->import( qw( Dump Load DumpFile LoadFile ) );
}#sub


1;