using YAML-based collapser
[scpubgit/stemmatology.git] / lib / Text / Tradition / TypeMap / Entry.pm
diff --git a/lib/Text/Tradition/TypeMap/Entry.pm b/lib/Text/Tradition/TypeMap/Entry.pm
new file mode 100644 (file)
index 0000000..00cdfd1
--- /dev/null
@@ -0,0 +1,42 @@
+package Text::Tradition::TypeMap::Entry;
+use Moose;
+
+no warnings 'recursion';
+
+use namespace::clean -except => 'meta';
+
+with qw(KiokuDB::TypeMap::Entry::Std);
+
+use YAML::XS ();
+
+sub compile_collapse_body {
+    my ( $self, $class ) = @_;
+
+    return sub {
+        my ( $self, %args ) = @_;
+
+        my $object = $args{object};
+
+        return $self->make_entry(
+            %args,
+            data => YAML::XS::Dump($object)
+        );
+    };
+}
+
+sub compile_expand {
+    my ( $self, $class ) = @_;
+
+    return sub {
+        my ( $self, $entry ) = @_;
+        $self->inflate_data( YAML::XS::Load($entry->data), \( my $obj ), $entry );
+
+        bless $obj, $class;
+    };
+}
+
+sub compile_refresh { return sub { die "TODO" } }
+
+__PACKAGE__->meta->make_immutable;
+
+1;