From: Matt S Trout Date: Thu, 18 Feb 2010 05:37:59 +0000 (+0000) Subject: commit changes before switch to new zoom API X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=71a02d85ebece24abbc547892dd252836cf1bf6d;p=catagits%2FApp-IdiotBox.git commit changes before switch to new zoom API --- diff --git a/lib/App/IdiotBox.pm b/lib/App/IdiotBox.pm index c59240c..0d7956a 100644 --- a/lib/App/IdiotBox.pm +++ b/lib/App/IdiotBox.pm @@ -33,9 +33,23 @@ use HTML::Zoom; } default_config( - template_dir => $FindBin::Bin.'/../share/html' + template_dir => 'share/html', + store => 'SQLite', + db_file => 'var/lib/idiotbox.db', ); +sub BUILD { + my $self = shift; + my $store; + ($store = $self->config->{store}) =~ /^(\w+)$/ + or die "Store config should be just a name, got ${store} instead"; + my $store_class = "App::IdiotBox::Store::${store}"; + eval "require ${store_class}; 1" + or die "Couldn't load ${store} store: $@"; + $store_class->bind($self); +} + + dispatch { sub (/) { $self->show_front_page }, subdispatch sub (/*/...) { @@ -44,7 +58,7 @@ dispatch { sub (/) { $self->show_bucket($bucket) }, - sub (/*) { + sub (/*/) { $self->show_video($bucket->videos->get({ slug => $_[1] })); } ] @@ -53,6 +67,8 @@ dispatch { method recent_announcements { $self->{recent_announcements} } +method buckets { $self->{buckets} } + method show_front_page { my $ann = $self->recent_announcements; $self->html_response( diff --git a/lib/App/IdiotBox/Store/SQLite.pm b/lib/App/IdiotBox/Store/SQLite.pm index 2bd60e6..377c87b 100644 --- a/lib/App/IdiotBox/Store/SQLite.pm +++ b/lib/App/IdiotBox/Store/SQLite.pm @@ -129,17 +129,15 @@ sub bind { bless({ idiotbox => $idiotbox }, $class)->_bind; } -my $DSN = 'dbi:SQLite:idiotbox.db'; - sub _new_db_store { - DBIx::Data::Store->connect($DSN); + DBIx::Data::Store->connect("dbi:SQLite:$_[1]"); } sub _bind { my $self = shift; my $idiotbox = $self->{idiotbox}; - my $db_store = $self->_new_db_store; + my $db_store = $self->_new_db_store($idiotbox->config->{db_file}); foreach my $to_bind (qw(recent_announcements buckets)) { $idiotbox->{$to_bind} = _bind_set($to_bind, { raw_store => $db_store }); diff --git a/script/idiotbox b/script/idiotbox old mode 100644 new mode 100755 diff --git a/t/show/front_page.t b/t/show/front_page.t index f7c67b3..623b0bf 100644 --- a/t/show/front_page.t +++ b/t/show/front_page.t @@ -5,8 +5,14 @@ use Test::More; use App::IdiotBox; use Data::Perl::Collection::Set; +BEGIN { $INC{"App/IdiotBox/Store/Test.pm"} = __FILE__ } + +sub App::IdiotBox::Store::Test::bind {} + my $idiotbox = App::IdiotBox->new({ - config => { template_dir => 'share/html' } + config => { + store => 'Test' + } }); my $ann = do {