David Helkowski > Class-Core-0.02 > Class::Core

Download:
Class-Core-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source   Latest Release: Class-Core-0.04

NAME ^

Class::Core - Class wrapper system providing parameter typing, logging, and class auto-instanitation

VERSION ^

0.02

SYNOPSIS ^

TestMod.pm

    package TestMod;
    use Class::Core;
    
    $spec = <<DONE;
    <func name='test'>
        <in name='input' type='number'/>
        <ret type='bool'/>
    </func>
    DONE

    sub new { return wrap_class( 'TestMod' ); }
    
    sub test {
        my ( $core, $self ) = @_;
        my $input = $core->get('input');
        return 0;
    }

Test.pl

    use TestMod;
    my $ob = new TestMod();
    $ob->test( input => '1' ); # will work fine
    $ob->test( input => 'string' ); # will cause an error

DESCRIPTION ^

This module is meant to provide a clean class/object system with the following features:

Function Parameter Validation

Input Parameters

    <func name='add'>
        <in name='a'/>
        <in name='b'/>
    </func>

Output Parameters

    <func name='add'>
        <out name='a'/>
        <out name='b'/>
    </func>

Classic Return Type

    <func name='check_okay'>
        <ret type='bool'/>
    </func>

Parameter Types

Number

The 'number' type validates that the parameter is numerical. Note that it does this by checked that adding 0 to the number does not affect it. Because of this trailing zeros will cause the validation to fail. This is expected and normal behavior.

The 'min' and 'max' attributes can be used to set the allowable numerical range.

Text

The 'text' type validates that the passed parameter is a literal string of some sort. ( as opposed to being a reference of some sort )

Date ( coming )

Path

The 'path' type validates that the passed parameter is a valid pathname.

The 'exists' attribute can be added to ensure there is a directory or file existing at the specified path.

The 'isdir' attribute can be used to check that the path is to a directory.

The 'isfile' attribute can be used to check that the path is to a file.

Boolean

The 'boolean' type validates that the passed parameter is either 0 or 1. Any other values will not validate.

Hash

The 'hash' type vlidates that the passed paramter is a reference to a hash, and then further validates the contents of the hash in the same way that parameters are validated.

    <func name='do_something'>
        <in name='person' type='hash'>
            <in name='name' type='text'/>
            <in name='age' type='number'/>
        </in>
    </func>

LICENSE ^

  Copyright (C) 2012 David Helkowski
  
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.  You may also can
  redistribute it and/or modify it under the terms of the Perl
  Artistic License.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
syntax highlighting: