Request a specific model to use in the storage helper
authorVincent Tondellier <tonton+hg@team1664.org>
Mon, 28 Dec 2015 21:36:14 +0100
changeset 83 eaf6d0ea4e65
parent 82 f15cbfb7a8e5
child 84 41164ea18780
Request a specific model to use in the storage helper
lib/CrashTest/Model/CrashReport.pm
lib/CrashTest/Model/Storage.pm
--- a/lib/CrashTest/Model/CrashReport.pm	Mon Dec 28 21:34:08 2015 +0100
+++ b/lib/CrashTest/Model/CrashReport.pm	Mon Dec 28 21:36:14 2015 +0100
@@ -19,19 +19,19 @@
 sub index {
     my ($self, $page, $nperpage, $search_str) = @_;
 
-    return $self->app->storage->first("index", $page, $nperpage, $search_str);
+    return $self->app->storage->first("CrashReport::index", $page, $nperpage, $search_str);
 }
 
 sub create {
     my ($self, $uuid, $pjson, $dump) = @_;
 
-    return $self->app->storage->each("create", $uuid, $pjson, $dump);
+    return $self->app->storage->each("CrashReport::create", $uuid, $pjson, $dump);
 }
 
 sub get_processed_data {
     my ($self, $uuid) = @_;
 
-    return $self->app->storage->first("get_processed_data", $uuid);
+    return $self->app->storage->first("CrashReport::get_processed_data", $uuid);
 }
 
 1;
--- a/lib/CrashTest/Model/Storage.pm	Mon Dec 28 21:34:08 2015 +0100
+++ b/lib/CrashTest/Model/Storage.pm	Mon Dec 28 21:36:14 2015 +0100
@@ -37,11 +37,12 @@
 sub each {
     my ($self, $proc, @args) = @_;
 
+    my ($mod, $func) = split(/::/, $proc, 2);
     my $result = 1;
     foreach my $storage(@{$self->instances}) {
-        if(defined(my $model = $storage->models->{CrashReport})) {
-            if($model->can($proc)) {
-                $result = $result && $model->$proc(@args);
+        if(defined(my $model = $storage->models->{$mod})) {
+            if($model->can($func)) {
+                $result = $result && $model->$func(@args);
             }
         }
     }
@@ -51,12 +52,13 @@
 sub first {
     my ($self, $proc, @args) = @_;
 
+    my ($mod, $func) = split(/::/, $proc, 2);
     my @result;
     foreach my $storage(@{$self->instances}) {
 
-        if(defined(my $model = $storage->models->{CrashReport})) {
-            if($model->can($proc)) {
-                @result = $model->$proc(@args);
+        if(defined(my $model = $storage->models->{$mod})) {
+            if($model->can($func)) {
+                @result = $model->$func(@args);
                 if(@result) {
                     last;
                 }