The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dicop::Item - a base class representing data objects

SYNOPSIS

        use base Dicop::Item;

REQUIRES

perl5.004, Exporter, Dicop::Base, Dicop::Event

EXPORTS

Exports nothing.

DESCRIPTION

This module offers a new() method which provides named parameters, and an _init() method, which you can override to do any initialisation your object needs.

FIELD

The following fields are present:

_modified
dirty

METHODS

_default()

Given a hash, initializes self with the values from the hash in case they are not already defined:

        $self->SUPER::_default( { name => 'unknown', blah => 9 } );

new_id()

Create a new, globally unique ID number for this item.

set_id()

Set the new globally ID number that will be used next by new_id() .

new()

        my $item = Dicop::Item->new();

Create a new empty item with default values for the fields.

If object templates were loaded, and a template exists for the requested class (f.i. "Dicop::Item"), then the template will be used to fill in the fields.

dirty()

Return the dirty flag. If given argument, sets the flag to that:

        print $item->dirty();           # 0 as default
        print $item->dirty(1);          # print 1

as_string()

Return the object as compact string to be saved to file or printed etc.

check()

Applies self-check and crumbles if there are errors in internal data structure.

from_file()

        $objects = [ Dicop::Item::from_file( $filename ) ];

Reconstruct objects from the string form loaded from a file, and return a list of these objects.

from_string()

        $objects = [ Dicop::Item::from_string( $string ) ];

From a string created with as_string, recreate the object(s). Returns a list of objects or a single one, depending on context (scalar/list).

keys()

        my @keys = $item->keys();

Returns a list of additional keys that must be included when generating HTML representations/lists. The list of keys is defined by the template.

get_as_string()

Convert data item from internal representation to a string suited for HTML presentation.

get_as_hex()

Just the same as get_as_string. You can override this method to convert certain (or all) keys to hexify before returning them. Good for strings that could contain unsafe or control characters.

get()

Return the value of a specified field of the object:

        $object->get('foo');

put()

Put the new value $value into the field called $key:

        $object->put($key,$value);

Note: For performance reasons, put() does not call modified(), so the object is not flagged as modified afterwards. You need to call modified() manually if you wish to mak the object as modified.

change()

Change a field's value after checking that the field can be changed (via can_change) and checking the new value. If the new value does not conform to the expected format, it will be silently modifed (f.i. invalid characters might be removed) and then the change will happen:

        $item->change('foo','bar');     # will change $object->{foo} to bar
                                        # if foo can be changed

can_change()

Return true if the field's value can be changed.

        die ("Can not change field $field\n") if !$object->can_change($field);

flush()

        $item->flush();

Override in a subclass to flush item to disk.

error()

        $item->error();

Return a potential error status of the object, or the empty string if no error occured.

copy()

        $evil_twin = $item->copy();

Makes a deep copy of the object including copies of sub-objects.

parent()

        my $parent = $item->parent();

Returns the parent object, e.g. the container we belong to.

fields()

        my @fields = $item->fields();

Return a list of additional keys that must be included when generating HTML representations or lists.

modified()

        $item->modified(1) unless $item->modified();

Returns true if the item was modified, and thus needs flushing.

If given a true or false argument, will set the modified flag to the corrosponding state.

template()

        my $tpl = $item->template();

Return the template for this class or undef if none exists.

BUGS

None known yet.

AUTHOR

(c) Bundesamt fuer Sicherheit in der Informationstechnik 1998-2006

DiCoP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

See http://www.bsi.de/ for more information.