Author image Marvin Humphrey
and 1 contributors

NAME

KinoSearch::Util::Class - Class-building utility.

PRIVATE CLASS

This is a private class and the interface may change radically and without warning. Do not use it on its own.

SYNOPSIS

    package KinoSearch::SomePackage::SomeClass;
    use base qw( KinoSearch::Util::Class );
    
    our %instance_vars = (
        # constructor params / members
        foo => undef,
        bar => {},

        # members
        baz => {},
    );

DESCRIPTION

KinoSearch::Util::Class is a class-building utility a la Class::Accessor, Class::Meta, etc. It provides three main services:

  1. A constructor with basic argument checking.

  2. Manufacturing of get_xxxx and set_xxxx methods.

  3. Convenience methods which help in defining abstract classes.

VARIABLES

%instance_vars

Each class which uses the inherited constructor needs to define an %instance_vars hash as a package global, which serves as a template for the creation of a hash-based object.

    our %instance_vars = (
        # constructor params / members
        foo => undef,
        bar => {},

        # members
        baz => '',
    );

%instance_vars may contain hashrefs and array-refs, as Clone's clone() method is used to produce a deep copy.

METHODS

new

A generic constructor with basic argument checking. new() expects hash-style labeled parameters; the label names must be present in the %instance_vars hash, or it will confess().

After verifying the labeled parameters, new() creates a deep clone of %instance_vars, and merges in the labeled arguments. It then calls $self->init_instance() before returning the blessed reference.

init_instance

    $self->init_instance();

Perform customized initialization routine. By default, this is a no-op.

ready_get_set ready_get ready_set

    # create get_foo(), set_foo(), get_bar(), set_bar() in __PACKAGE__
    BEGIN { __PACKAGE__->ready_get_set(qw( foo bar )) };

Mass manufacture getters and setters. The setters do not return a meaningful value.

abstract_death todo_death

    sub an_abstract_method      { shift->abstract_death }
    sub maybe_someday           { shift->todo_death }

These are just different ways to die(), and are of little interest until your particular application comes face to face with one of them.

abstract_death indicates that a method must be defined in a subclass.

todo_death indicates a feature that might get implemented someday.

COPYRIGHT

Copyright 2005-2007 Marvin Humphrey

LICENSE, DISCLAIMER, BUGS, etc.

See KinoSearch version 0.20.