X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FCollation%2FReading%2FWordForm.pm;fp=lib%2FText%2FTradition%2FCollation%2FReading%2FWordForm.pm;h=6a6b56bf60ca85ee8e1f02a80f2183e920fcca7a;hb=7604424bc5cc004f536d20099d9d348aa922ce7d;hp=46a9f80a3a60838ca4e1b0cfcbb2ed2881bb8443;hpb=70745e700723084e7f980b0bf65ce8e134931f44;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Collation/Reading/WordForm.pm b/lib/Text/Tradition/Collation/Reading/WordForm.pm index 46a9f80..6a6b56b 100644 --- a/lib/Text/Tradition/Collation/Reading/WordForm.pm +++ b/lib/Text/Tradition/Collation/Reading/WordForm.pm @@ -1,7 +1,8 @@ package Text::Tradition::Collation::Reading::WordForm; -use Moose; use Lingua::Features::Structure; +use JSON (); +use Moose; =head1 NAME @@ -66,11 +67,11 @@ around BUILDARGS => sub { my $orig = shift; my $class = shift; my $args = @_ == 1 ? $_[0] : { @_ }; - if( exists $args->{'serial'} ) { - my( $lang, $lemma, $morph ) = split( /\+\+/, delete $args->{'serial'} ); - $args->{'language'} = $lang; - $args->{'lemma'} = $lemma; - $args->{'morphology'} = Lingua::Features::Structure->from_string( $morph ); + if( exists $args->{'JSON'} ) { + my $data = $args->{'JSON'}; + my $morph = Lingua::Features::Structure->from_string( $data->{'morphology'} ); + $data->{'morphology'} = $morph; + $args = $data; } $class->$orig( $args ); }; @@ -84,7 +85,16 @@ in equivalence testing. sub to_string { my $self = shift; - return join( '++', $self->language, $self->lemma, $self->morphology->to_string ); + return JSON->new->convert_blessed(1)->encode( $self ); +} + +sub TO_JSON { + my $self = shift; + return { + 'language' => $self->language, + 'lemma' => $self->lemma, + 'morphology' => $self->morphology->to_string + }; } no Moose;