| sofu documentation | Contained in the sofu distribution. |
Data::Sofu::Value - A Sofu Value
Provides a interface similar to the original SofuD (sofu.sf.net)
require Data::Sofu::Value;
my $v = Data::Sofu::Value->new();
$v->set("Hello World");
This Module is pure OO, exports nothing
Also look at Data::Sofu::Object for methods, cause Value inherits from it
Creates a new Data::Sofu::Value and returns it
Converts DATA to a string if DATA is given.
$val = Data::Sofu::Value->new("Hello World");
Sets the contents of this Value (replaces the old contents).
Note: DATA will be converted to a string.
$v->set("Foobar");
Returns itself, used to make sure this Value is really a Value (Data::Sofu::Map and Data::Sofu::List will die if called with this method)
Perl only
Returns this Value as a perl Scalar (same as toString)
Returns this as a string
toUTF16(), toUTF8(), toUTF32()Not working in Perl (cause there is no wchar, char, dchar stuff going on, if you need to convert strings use "Encode")
They just return the same as toString()
Return the Value as an Integer
$v->toInt() === int $v->toString();
Return the Value as a Float
$v->toFloat() === $v->toString()+0;
Return the Value as a Long
$v->toLong() === int $v->toString();
Return the Value as a Double
$v->toDouble() === $v->toString()+0;
Returns 1
stringify(LEVEL,TREE)Returns a string representation of this Value.
LEVEL and TREE are ignored...
binarify(TREE,BINARY DRIVER)Returns the binary version of this Value using the BINARY DRIVER. Don't call this one, use binaryPack instead.
most of the methods do the same, because perl does the converting for you.
| sofu documentation | Contained in the sofu distribution. |
############################################################################### #Value.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::Value; use strict; use warnings; require Data::Sofu::Object; require Data::Sofu::List; require Data::Sofu::Undefined; require Data::Sofu; our @ISA = qw/Data::Sofu::Object/; our $VERSION="0.29";
sub new { my $self={}; bless $self,shift; $$self{Value}=undef; $$self{Value}="".shift if @_; if (@_) { return Data::Sofu::List->new($$self{Value},@_); } return $self if defined $$self{Value}; return Data::Sofu::Undefined->new(); }
sub set { my $self=shift; $$self{Value}="".shift; }
sub asValue { return shift; }
sub asScalar { my $self=shift; return $$self{Value}; }
sub toString { my $self=shift; return $$self{Value}; }
#TODO sub toUTF16 { my $self=shift; return $$self{Value}; } sub toUTF8 { my $self=shift; return $$self{Value}; } sub toUTF32 { my $self=shift; return $$self{Value}; } #/TODO
sub toInt { my $self=shift; return int $$self{Value}; }
sub toFloat { my $self=shift; return $$self{Value}+0; }
sub toLong { my $self=shift; return int $$self{Value}; }
sub toDouble { my $self=shift; return $$self{Value}+0; }
sub isValue { return 1 } #=head2 string() #Same as Data::Sofu::Object::string(), but skips the Reference building. #=cut #sub string { #No References for Values at this time (just remove this function to enable them # my $self=shift; # return $self->stringify(@_); #}
sub stringify { my $self=shift; my $level=shift; my $tree=shift; return "Value = ".Data::Sofu::Sofuescape($$self{Value}).$self->stringComment()."\n" unless $level; return Data::Sofu::Sofuescape($$self{Value}).$self->stringComment()."\n"; }
sub binarify { my $self=shift; my $tree=shift; my $bin=shift; my $str=$bin->packType(1); $str.=$self->packComment($bin); $str.=$bin->packText($$self{Value}); return $str; }
1;