The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Flail::Thing - A structured thing

VERSION

  Time-stamp: <2006-12-01 16:35:16 attila@stalphonsos.com>
  $Id: Thing.pm,v 1.3 2006/04/26 03:52:03 attila Exp $

SYNOPSIS

  package Something;
  use base qw(Flail::Thing);
  sub _struct {
      return shift->SUPER::_struct,
              ( my_field_1 => default_value,
                my_field_2 => default_value, );
  }

  package main;
  my $obj = Something->new(my_field_1 => 1, my_field_2 => 'blah');
  print $obj->as_string."\n";  ## can turn them into strings
  print $obj->my_field_2."\n"; ## print the value of a field
  $obj->my_field_1(3);         ## set my_field_1 to 3

  sub terlet {
    my($obj,@changes) = @_;
    while (@changes) {
      my($name,$val) = splice(@changes,0,2);
      print "$obj $name => $val\n";
    }
    return undef;
  }

  $obj->FLUSH(\&terlet);      ## will be called with: my_field_1 => 3

DESCRIPTION

This is a generic thing. It has slots. Slots can contain other things, but swizzling and unswizzling don't happen automagically.

It is derived from a class I wrote a long time ago called just plain old Thing. I am pulling it into Flail starting in version 0.2.0.

Things can have options. Options are not slots, they are used to specify optional attributes of an object regardless of its particular structure or behavior. For instance, the autoflush attribute can be used to tell the DESTROY method in Thing whether or not to flush changes to an object that is being garbage-collected by the Perl interpreter.

as_string()

Return a human-readable string that represents this object.

eval ...

Perform some arbitrary "evaluation" function as per the semantics of the object.

FLUSH $callback,@args

Invoke the callback function with $self, and one $attr => $val pair. Each invocation represents one state change that has not yet been stored presistently. The callback's job is to store this state change, in whatever way makes sense for the object.

LOAD $callback,@args...

Invoked to load state from whatever persistent store this object uses. We are passed a list of slots that are missing.

OPTION $opt => $newval

Check optional attributes for this object, or set them.

AUTHOR

Sean Levy <snl@cluefactory.com>

COPYRIGHT AND LICENSE

(C) 2002-2006 by Sean Levy <snl@cluefactory.com>. all rights reserved.

This code is released under a BSD license. Please see the LICENSE file that came with the source distribution or visit http://flail.org/LICENSE