NAME

PogoLink - Bidirectional relationship class for Pogo objects

SYNOPSIS

use PogoLink;
package Person;
sub new {
    my($class, $pogo, $name) = @_;
    # Make a hash ref persistent by $pogo and blessed by $class
    my $self = new_tie Pogo::Hash 8, $pogo, $class;
    %$self = (
        NAME     => $name,
        FATHER   => new PogoLink::Scalar($self, 'Man',    'CHILDREN'),
        MOTHER   => new PogoLink::Scalar($self, 'Woman',  'CHILDREN'),
        FRIENDS  => new PogoLink::Btree ($self, 'Person', 'FRIENDS', 'NAME'),
    );
    $self;
}
package Man;
@ISA = qw(Person);
sub new {
    my($class, $pogo, $name) = @_;
    my $self = $class->SUPER::new($pogo, $name);
    $self->{CHILDREN} = new PogoLink::Array ($self, 'Person', 'FATHER');
    $self->{WIFE}     = new PogoLink::Scalar($self, 'Woman',  'HUS');
    $self;
}
package Woman;
@ISA = qw(Person);
sub new {
    my($class, $pogo, $name) = @_;
    my $self = $class->SUPER::new($pogo, $name);
    $self->{CHILDREN} = new PogoLink::Array ($self, 'Person', 'MOTHER');
    $self->{HUS}      = new PogoLink::Scalar($self, 'Man',    'WIFE');
    $self;
}
$Pogo = new Pogo 'sample.cfg';
$Root = $Pogo->root_tie;
$Root->{PERSONS} = new Pogo::Btree;
$Persons = $Root->{PERSONS};
$Dad = $Persons->{Dad} = new Man   $Pogo, 'Dad';
$Mom = $Persons->{Mom} = new Woman $Pogo, 'Mom';
$Jr  = $Persons->{Jr}  = new Man   $Pogo, 'Jr';
$Gal = $Persons->{Gal} = new Woman $Pogo, 'Gal';
# Marriage 
$Dad->{WIFE}->add($Mom);     # $Mom->{HUS} links to $Dad automatically
# Birth
$Dad->{CHILDREN}->add($Jr);  # $Jr->{FATHER} links to $Dad automatically
$Mom->{CHILDREN}->add($Jr);  # $Jr->{MOTHER} links to $Mom automatically
# Jr gets friend
$Jr->{FRIENDS}->add($Gal);   # $Gal->{FRIENDS} links to $Jr automatically
# Oops! Gal gets Dad
$Gal->{HUS}->add($Dad);      # $Dad->{WIFE} links to $Gal automatically
                             # $Mom->{HUS} unlinks to $Dad automatically

DESCRIPTION

PogoLink makes single-single or single-multi or multi-multi bidirectional relationships between Pogo objects. The relationships are automatically maintained to link each other correctly. You can choose one of Pogo::Array, Pogo::Hash, Pogo::Htree, Pogo::Btree and Pogo::Ntree to make a multi end of link.

Classes

PogoLink::Scalar

This class makes a single end of link.

PogoLink::Array

This class makes a multi end of link as an array. It uses Pogo::Array to have links.

PogoLink::Hash, PogoLink::Htree, PogoLink::Btree, PogoLink::Ntree

These classes make a multi end of link as a hash. Each uses corresponding Pogo::* to have links.

Methods

new PogoLink::* $selfobject, $linkclass, $invattr, $keyattr

Constructor. Class method. $selfobject is a Pogo persistent object which possesses this link. It must be a object as a hash reference. $linkclass is a class name of linked object. If $linkclass defaults, any class object is allowed. $invattr is an attribute (i.e. hash key) name of the linked object which links inversely. $keyattr is only necessary for PogoLink::Hash, PogoLink::Htree, PogoLink::Btree, PogoLink::Ntree. It specifies an attribute name of the linked object thats value is used as the key of this link hash.

get $idx_or_key

Get the linked object. For PogoLink::Scalar, $idx_or_key is not necessary. For PogoLink::Array, $idx_or_key is an array index number. For other, $idx_or_key is a hash key string.

getlist

Get the linked object list.

getkeylist

Get the hash key list of linked objects. Only available for PogoLink::Hash, PogoLink::Htree, PogoLink::Btree, PogoLink::Ntree.

find $object

Test the link if it links to $object.

clear

Unlink to all objects in the link.

del $object

Unlink to $object.

add $object

Link to $object.

AUTHOR

Sey Nakajima <sey@jkc.co.jp>

SEE ALSO

Pogo(3).

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 273:

You forgot a '=back' before '=head2'

Around line 275:

'=item' outside of any '=over'

Around line 289:

You forgot a '=back' before '=head2'

Around line 291:

'=item' outside of any '=over'