1 package Text::Tradition::Directory;
7 use KiokuDB::TypeMap::Entry::Naive;
9 extends 'KiokuX::Model';
13 default => sub { {} },
17 add_tradition => 'set',
25 isa => 'KiokuDB::TypeMap',
27 KiokuDB::TypeMap->new(
29 "Graph::Easy::Base" => KiokuDB::TypeMap::Entry::Naive->new,
30 "Graph" => KiokuDB::TypeMap::Entry::Naive->new,
31 "Graph::AdjacencyMap" => KiokuDB::TypeMap::Entry::Naive->new,
37 around 'tradition' => sub {
38 my( $orig, $self, @arg ) = @_;
39 my $data = $self->$orig( @arg );
40 return $data->{'object'};
43 around 'stemma' => sub {
44 my( $orig, $self, @arg ) = @_;
45 my $data = $self->$orig( @arg );
46 return $data->{'stemma'};
49 around 'add_tradition' => sub {
50 my( $orig, $self, $id, $obj ) = @_;
51 $self->$orig( $id => { 'object' => $obj } );
54 around 'add_stemma' => sub {
55 my( $orig, $self, $id, $obj ) = @_;
56 $self->{data_hash}->{$id}->{'stemma'} = $obj;
59 # Load all the relevant data from the DSN we were passed.
65 if( exists $args->{'dsn'} ) {
66 # Connect to self, get the traditions and stemmas, and save them
68 my $scope = $self->new_scope;
69 my $stream = $self->root_set;
71 until( $stream->is_done ) {
72 foreach my $obj ( $stream->items ) {
73 my $uuid = $self->object_to_id( $obj );
74 if( ref( $obj ) eq 'Text::Tradition' ) {
75 $self->add_tradition( $uuid => $obj );
76 } elsif( ref( $obj ) eq 'Text::Tradition::Stemma' ) {
77 $stemmata{$obj->collation} = $obj;
79 warn "Found root object in DB that is neither tradition nor stemma: $obj";
83 # Now match the stemmata to their traditions.
84 foreach my $id ( $self->traditions ) {
85 my $c = $self->tradition( $id )->collation;
86 if( exists $stemmata{$c} ) {
87 $self->add_stemma( $id => $stemmata{$c} );