ascray has asked for the wisdom of the Perl Monks concerning the following question:
Derived class: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;
Using in app: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;
Works fine. Only while $body is non-UTF-8 string.
In other case $msg->body($body) produces strange pause (15-60 secs) with 100% CPU load.
Any ideas?
$ perl -v This is perl, v5.8.9 built for i386-freebsd-64int
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange AUTOLOAD's bevavior with utf8 data
by almut (Canon) on Apr 29, 2009 at 10:54 UTC | |
by ascray (Initiate) on Apr 29, 2009 at 13:01 UTC | |
by ikegami (Patriarch) on Apr 29, 2009 at 13:48 UTC |