From: Tara L Andrews Date: Wed, 21 Dec 2011 22:11:11 +0000 (+0100) Subject: convert Catalyst app to use KiokuDB backend X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3837c155d39333869a93adf1e8375960ffbf3a92;p=scpubgit%2Fstemmatology.git convert Catalyst app to use KiokuDB backend --- diff --git a/TreeOfTexts/Makefile.PL b/TreeOfTexts/Makefile.PL index 3fa3531..e20b64b 100644 --- a/TreeOfTexts/Makefile.PL +++ b/TreeOfTexts/Makefile.PL @@ -14,7 +14,7 @@ requires 'Catalyst::Plugin::ConfigLoader'; requires 'Catalyst::Plugin::Static::Simple'; requires 'Catalyst::Plugin::Unicode::Encoding'; requires 'Catalyst::Action::RenderView'; -requires 'Catalyst::Model::Adaptor'; +requires 'Catalyst::Model::KiokuDB'; requires 'Moose'; requires 'namespace::autoclean'; requires 'Config::General'; # This should reflect the config file format you've chosen diff --git a/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm b/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm index 82cc961..9707dfa 100644 --- a/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm +++ b/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm @@ -1,7 +1,8 @@ package TreeOfTexts::Controller::Root; use Moose; use namespace::autoclean; -use TreeOfTexts::Model::Analysis qw/ run_analysis /; +use Text::Tradition::Analysis qw/ run_analysis /; + BEGIN { extends 'Catalyst::Controller' } @@ -30,20 +31,39 @@ The root page (/) sub index :Path :Args(0) { my ( $self, $c ) = @_; - my $m = $c->model('Analysis'); - my $i = 0; - my @all_texts = map { $_->{'title'} } @{$m->{'data'}}; + my $m = $c->model('Directory'); + my @all_texts; + foreach my $id ( $m->traditions ) { + my $data = { + 'id' => $id, + 'name' => $m->tradition( $id )->name, + 'has_stemma' => defined $m->stemma( $id ), + }; + push( @all_texts, $data ); + } + $c->stash->{texts} = \@all_texts; $c->stash->{template} = 'frontpage.tt'; } -sub view_text :Local { +sub relationships :Local { + my( $self, $c ) = @_; + my $m = $c->model('Directory'); + my $tradition = $m->tradition( $c->request->params->{'textid'} ); + $c->stash->{alignment} = $tradition->collation->make_alignment_table( 'refs' ); + $c->stash->{template} = 'relationships.tt'; +} + +sub stexaminer :Local { my( $self, $c ) = @_; - my $m = $c->model('Analysis'); - my $t = $m->{'data'}->[ $c->request->params->{'textid'} ]; - $c->stash->{svg} = $t->{'svg'}; + my $m = $c->model('Directory'); + my $id = $c->request->params->{'textid'}; + my $tradition = $m->tradition( $id ); + my $stemma = $m->stemma( $id ); + my $t = run_analysis( $tradition, $stemma ); + $c->stash->{svg} = $stemma->as_svg; $c->stash->{variants} = $t->{'variants'}; - $c->stash->{text_title} = $t->{'title'}; + $c->stash->{text_title} = $tradition->name; $c->stash->{total} = $t->{'variant_count'}; $c->stash->{genealogical} = $t->{'genealogical_count'}; $c->stash->{conflict} = $t->{'conflict_count'}; @@ -52,21 +72,23 @@ sub view_text :Local { sub view_table :Local { my( $self, $c ) = @_; - my $m = $c->model( 'Analysis' ); - my $t = $m->{'data'}->[ $c->request->params->{'textid'} ]; + my $m = $c->model('Directory'); + my $id = $c->request->params->{'textid'}; + my $t = run_analysis( $m->tradition( $id ), $m->stemma( $id ) ); $c->stash->{variants} = $t->{'variants'}; $c->stash->{template} = 'table_gadget.tt'; } sub view_svg :Local { my( $self, $c ) = @_; - my $m = $c->model( 'Analysis' ); - my $t = $m->{'data'}->[ $c->request->params->{'textid'} ]; - $c->stash->{svg} = $t->{'svg'}; + my $m = $c->model('Directory'); + my $stemma = $m->stemma( $c->request->params->{'textid'} ); + if( $stemma ) { + $c->stash->{svg} = $stemma->as_svg; + } $c->stash->{template} = 'stemma_gadget.tt'; } - =head2 default Standard 404 error page diff --git a/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm b/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm index d0c4acb..1d6a8e0 100644 --- a/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm +++ b/TreeOfTexts/lib/TreeOfTexts/Controller/Stemmagraph.pm @@ -15,7 +15,7 @@ __PACKAGE__->config(namespace => ''); =head1 NAME -TreeOfTexts::Controller::Root - Root Controller for TreeOfTexts +TreeOfTexts::Controller::Stemmagraph - Simple controller for stemma display =head1 DESCRIPTION @@ -32,7 +32,6 @@ sub get_graph :Local { # The body is actually a File::Temp object; this is undocumented but # so it seems to be. my $dotfile; - $DB::single = 1; my $must_unlink = 0; if( $c->request->params->{'dot'} ) { # Make a File::Temp object. diff --git a/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm b/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm deleted file mode 100644 index 08b8e0d..0000000 --- a/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm +++ /dev/null @@ -1,24 +0,0 @@ -package TreeOfTexts::Model::Analysis; - -use strict; -use warnings; - -use base 'Catalyst::Model::Adaptor'; - -__PACKAGE__->config( - class => 'Text::Tradition::Analysis', - args => { 'traditions' => [ - { 'file' => TreeOfTexts->path_to( 't', 'data', 'florilegium.xml' ), - 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_a.dot' ) }, - { 'file' => TreeOfTexts->path_to( 't', 'data', 'besoin.xml' ), - 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_b.dot' ) }, - { 'file' => TreeOfTexts->path_to( 't', 'data', 'heinrichi.xml' ), - 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_h.dot' ) }, - { 'file' => TreeOfTexts->path_to( 't', 'data', 'parzival.xml' ), - 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_p.dot' ) }, - { 'file' => TreeOfTexts->path_to( 't', 'data', 's158.xml' ), - 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_s.dot' ) }, - ] }, - ); - -1; diff --git a/TreeOfTexts/lib/TreeOfTexts/Model/Directory.pm b/TreeOfTexts/lib/TreeOfTexts/Model/Directory.pm new file mode 100644 index 0000000..937d391 --- /dev/null +++ b/TreeOfTexts/lib/TreeOfTexts/Model/Directory.pm @@ -0,0 +1,11 @@ +package TreeOfTexts::Model::Directory; +use strict; +use warnings; +use Moose; +use Text::Tradition::Directory; + +extends 'Catalyst::Model::KiokuDB'; + +has '+model_class' => ( default => 'Text::Tradition::Directory' ); + +1; diff --git a/TreeOfTexts/root/src/frontpage.tt b/TreeOfTexts/root/src/frontpage.tt index 7ba54d2..218405d 100644 --- a/TreeOfTexts/root/src/frontpage.tt +++ b/TreeOfTexts/root/src/frontpage.tt @@ -6,7 +6,10 @@