I've been going a bit crazy with the to/from yaml for serialization

I noticed that YAML::Syck / JSON::Syck can sometimes have a blank  
line in it, which can screw the parser up, and then the rose reader

This will fix it:

        next unless $column;

where?

Rose::DB::Object::Helpers
        sub init_with_yaml
        sub init_with_json

sub init_with_yaml
{
   my($self, $yaml) = @_;

   my $hash = YAML::Syck::Load($yaml);
   my $meta = $self->meta;

   local $self->{STATE_LOADING()} = 1;

   while(my($column, $value) = each(%$hash))
   {
     next unless $column;
     my $method = $meta->column($column)->mutator_method_name;
     $self->$method($value);
   }

   return $self;
}

sub init_with_json
{
   my($self, $json) = @_;

   my $hash = JSON::Syck::Load($json);
   my $meta = $self->meta;

   local $self->{STATE_LOADING()} = 1;

   while(my($column, $value) = each(%$hash))
   {
     next unless $column;
     my $method = $meta->column($column)->mutator_method_name;
     $self->$method($value);
   }

   return $self;
}



Also....

what about consolidating both functions a bit, and adding  
'init_with_hashref' ?

i say this because:
        a- i'm using an init_with_hashref already
        b- init_with_yaml / init_with_json have 80% of the same  
functionality.  we could save some memory here.

so....

sub init_with_hashref
{
   my($self, $hashref) = @_;
   my $meta = $self->meta;
   local $self->{STATE_LOADING()} = 1;
   while(my($column, $value) = each(%$hashref))
   {
     next unless $column;
     my $method = $meta->column($column)->mutator_method_name;
     $self->$method($value);
   }
   return $self;
}

sub init_with_yaml
{
   my($self, $yaml) = @_;
   my $hash = YAML::Syck::Load($yaml);
   $self-> init_with_hashref( $hash );
   return $self;
}

sub init_with_json
{
   my($self, $json) = @_;
   my $hash = JSON::Syck::Load($json);
   $self-> init_with_hashref( $hash );
   return $self;
}




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to