package XNObject;
use strict;
sub new {
my $class = shift;
my %fields = (
_modified => 0,
_actual => 0,
_f => {}, # "real" object fields
);
my $self = {
%fields,
};
bless $self, $class;
}
our $AUTOLOAD;
sub AUTOLOAD {
my $self = shift;
my $value = shift;
my $type = ref($self)
or croak "No class for AUTOLOAD";
my $name = $AUTOLOAD;
$name =~ s/.*://;
if(defined($value)){
return $self->{_f}->{$name} = $value;
}else{
return $self->{_f}->{$name};
}
}
# other stuff skipped
1;
####
package ForumMessage;
use strict;
use base qw(XNObject);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my %fields = (
_type => 'forum_message',
);
@{$self}{keys %fields} = values %fields;
bless $self, $class;
}
#other stuff skipped
1;
####
use strict;
use ForumMessage;
my $msg = ForumMessage->new;
my $body = "This is a test"; # utf8 string here
$msg->body($body); # strange pause with utf8 string
print $msg->body; # works fine with any data
#$msg->user_id($user_id);
#$msg->_store;
####
$ perl -v
This is perl, v5.8.9 built for i386-freebsd-64int