## HiPi::Class

HiPi::Class is a base module used throughout HiPi to provide a base for other OO classes.

Most long term Perl addicts resort to their own class creation helpers at some point and I am no exception.

If you are new to Perl, you would be better to investigate the Moose modules as a basis for writing your own OO code, or perhaps even Class::Accessor and friends.

As the great Burt Bacharach once said, you must learn the rules before you can break them.

The module is only documented for explanation as it appears throughout the code

### Accessor Creation Methods

    __PACKAGE->creat_accessors( qw( methodname ) );

    # creates a read/write accessor
    my $val = $obj->methodname();
    $obj->methodname($val);

    __PACKAGE->creat_ro_accessors( qw( methodname ) );

    # creates a read only accessor
    my $val = $obj->methodname();

    __PACKAGE->creat_get_accessors( qw( methodname ) );

    # creates a read accessor prefixed with 'get_'
    my $val = $obj->get_methodname();

    __PACKAGE->creat_set_accessors( qw( methodname ) );

    # creates a write accessor prefixed with 'set_'
    $obj->set_methodname($val);

    __PACKAGE->creat_both_accessors( qw( methodname ) );

    # calls creat_get_accessors() and creat_set_accessors()

    NOTE: Capitilised method names produce capitalised
          accessors without an underscore

    __PACKAGE->creat_get_accessors( qw( MethodName ) );

    # creates a read accessor prefixed with 'Get'
    my $val = $obj->GetMethodName();

    __PACKAGE->creat_set_accessors( qw( MethodName ) );

    # creates a write accessor prefixed with 'Set'
    $obj->SetMethodName($val);

### Example Usage

    package MyBot;
    use strict;
    use warnings;
    use parent ( HiPi::Class );

    __PACKAGE->creat_accessors( qw( name arms legs winsprize ) );

    sub new {
        my($class, %params) = @_;
        my $this = $class->SUPER::new(%params);
        return $this;
    }

    package main;

    my $mate = MyBot->new(
        name => 'Eric',
        arms => 2,
        legs => 2
    );

    print 'legs ', $mate->legs;
    print 'arms ', $mate->arms;

    $mate->winsprize('yes');

HiPi Modules Copyright © 2013 - 2016 Mark Dootson