NAME
Class::Core - Class wrapper system providing parameter typing, logging, and class auto-instanitation
VERSION
0.04
SYNOPSIS
TestMod.pm.xml
<func name='test'>
<in name='input' type='number'/>
<ret type='bool'/>
</func>
TestMod.pm
package TestMod;
use Class::Core qw/:all/;
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:
Wrapped functions
All class functions are wrapped and used indirectly
Named parameters
Function parameters are always passed by name
<func name='add'> <in name='a'/> <in name='b'/> </func>
Parameter Type Checking
Function parameters are type checked based on a provided specification in XML
<func name='add'> <in name='a' type='number'/> <in name='b' type='number'/> </func>
Function Overloading
Functions can be overloaded by using multiple typed function "signatures"
<func name='runhash'> <sig> <in name='recurse' type='bool' optional/> <in name='path' type='path' isdir/> <set name='mode' val='dir'/> </sig> <sig> <in name='path' type='path' isfile/> <set name='mode' val='file'/> </sig> </func>
Each 'sig' ( signature ) will be checked in order till one of them validates. The first one to validate is used. The 'set' node are run on the signature that validates.
Automatic Object Instantiation ( coming )
Classes are automatically instantiated when needed based on dependencies
Object States ( coming )
Classes / Objects can have multiple states
Automatic State Change ( coming )
Class methods may require their owning object to be in a specific case in order to run ( in which case the proper function to change states will be called automatically )
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) 2013 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.