| sofu documentation | Contained in the sofu distribution. |
Data::Sofu::Reference - A Sofu Reference
Provides a interface similar to the original SofuD (sofu.sf.net).
References present a transparent interface to the object referenced. Normally they shouldn't even bother you one bit.
require Data::Sofu::Map;
require Data::Sofu::Reference;
my $map = Data::Sofu::Map->new();
$map->setAttribute("myself",Data::Sofu::Reference->new($map)); #Reference to itself.
$map->map("myself"); #Will return $map not the Reference.
$map->object("myself")->asReference(); #Will return the Reference.
$map->object("myself")->asMap(); #will return the Map.
$map->object("myself")->isMap(); #True
$map->map("myself")->isMap(); #Also true
$map->object("myself")->isReference(); #True
$map->map("myself")->isReference(); #false (you skipped the reference when using map());
#You can also:
my $map = Data::Sofu::Map->new();
$map->setAttribute("myself",$map); #Will be converted to Reference as soon as it is written to a file or string.
This Module is pure OO, exports nothing
Also look at Data::Sofu::Object for methods, cause Reference inherits from it
Data::Sofu::Reference and returns it $ref = Data::Sofu::Reference->new("->myself"); #Tree form, not valid (just for saving data)
my $map = Data::Sofu::Map->new();
$ref = Data::Sofu::Reference->new($map); #Valid
Changes the target of the Reference to Data
Return 1 if the Reference is there and points to something that is a Data::Sofu::Object
Return 1 if the Reference is there and points to something that is a Data::Sofu::Object
Returns 1
Returns the referenced object, valid or not.
Returns the referenced objects asValue() call.
Which Returns either the referenced object or throws an exception
Returns the referenced objects asMap() call.
Which Returns either the referenced object or throws an exception
Returns the referenced objects asList() call.
Which Returns either the referenced object or throws an exception
Returns 1 if the Reference is valid and the referenced Object is a List.
Returns 1 if the Reference is valid and the referenced Object is a Value.
Returns 1 if the Reference is valid and the referenced Object is a Map.
Returns 1 if the Reference is valid and the referenced Object is defined (i.e. not a Data::Sofu::Undefined).
Returns itself
Referencing something else than a Data::Sofu::Object or derieved will not convert the referenced thing and it will confuse the write() to produce invalid sofu files.
| sofu documentation | Contained in the sofu distribution. |
############################################################################### #Reference.pm #Last Change: 2006-11-01 #Copyright (c) 2006 Marc-Seabstian "Maluku" Lucksch #Version 0.28 #################### #This file is part of the sofu.pm project, a parser library for an all-purpose #ASCII file format. More information can be found on the project web site #at http://sofu.sourceforge.net/ . # #sofu.pm is published under the terms of the MIT license, which basically means #"Do with it whatever you want". For more information, see the license.txt #file that should be enclosed with libsofu distributions. A copy of the license #is (at the time of this writing) also available at #http://www.opensource.org/licenses/mit-license.php . ###############################################################################
package Data::Sofu::Reference; use strict; use warnings; require Data::Sofu::Object; our @ISA = qw/Data::Sofu::Object/; our $VERSION="0.29"; use vars qw/$AUTOLOAD/;
sub new { my $self={}; bless $self,shift; if (@_) { $self->{Reference}=shift; } return $self; }
sub dangle { my $self=shift; $self->{Reference}=shift; }
sub valid { my $self=shift; my $r = ref $self->{Reference}; return 1 if $r and $r=~m/Data::Sofu/ and $self->{Reference}->isa("Data::Sofu::Object"); return 0; }
sub isValid { my $self=shift; my $r = ref $self->{Reference}; return 1 if $r and $r=~m/Data::Sofu/ and $self->{Reference}->isa("Data::Sofu::Object"); return 0; }
sub isReference { return 1; }
sub follow { my $self=shift; return $self->{Reference}; }
sub asValue { my $self=shift; die "Invalid Reference" unless $self->isValid(); return $self->{Reference}->asValue(); }
sub asMap { my $self=shift; die "Invalid Reference" unless $self->isValid(); return $self->{Reference}->asMap(); }
sub asList { my $self=shift; die "Invalid Reference" unless $self->isValid(); return $self->{Reference}->asList(); }
sub isList { my $self=shift; return $self->isValid() && $self->{Reference}->isList(); }
sub isValue { my $self=shift; return $self->isValid() && $self->{Reference}->isValue(); }
sub isMap { my $self=shift; return $self->isValid() && $self->{Reference}->isMap(); }
sub isDefined { my $self=shift; return $self->isValid() && $self->{Reference}->isDefined(); }
sub asReference { return shift; } #Experimental (Work with References as if they were transparent) #sub AUTOLOAD { # my $self=shift; # my $x=$AUTOLOAD; # $x=~s/^.+:://g; # #die $x; # return $self->{Reference}->$x(@_); #} #sub DESTROY { # my $self=shift; # $self->{Reference}=undef; #} #
1;