File Coverage

blib/lib/RapidApp/Module/StorCmp/Role/DbicLnk/RowPg.pm
Criterion Covered Total %
statement 12 22 54.5
branch 0 4 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 0 2 0.0
total 16 37 43.2


line stmt bran cond sub pod time code
1             package RapidApp::Module::StorCmp::Role::DbicLnk::RowPg;
2              
3 4     4   3004 use strict;
  4         11  
  4         121  
4 4     4   22 use warnings;
  4         9  
  4         121  
5              
6             # ABSTRACT: for DbicLnk modules to display a single Row instead of multiple
7              
8 4     4   21 use Moose::Role;
  4         8  
  4         38  
9              
10             # From RapidApp::Module::StorCmp::Role::DbicLnk, which must be loaded first
11             requires 'allow_restful_queries';
12              
13              
14 4     4   19106 use RapidApp::Util qw(:all);
  4         11  
  4         3619  
15              
16             has 'getTabTitle', is => 'ro', isa => 'Maybe[CodeRef]', default => undef;
17             has 'getTabIconCls', is => 'ro', isa => 'Maybe[CodeRef]', default => undef;
18              
19             sub supplied_id {
20 0     0 0   my $self = shift;
21 0           my $id = $self->c->req->params->{$self->record_pk};
22 0 0 0       if (not defined $id and $self->c->req->params->{orig_params}) {
23 0           my $orig_params = $self->json->decode($self->c->req->params->{orig_params});
24 0           $id = $orig_params->{$self->record_pk};
25             }
26 0           return $id;
27             }
28              
29             sub ResultSet {
30 0     0 0   my $self = shift;
31 0           my $Rs = shift;
32              
33 0 0         my $value = $self->supplied_id or return $Rs;
34 0           return $Rs->search_rs($self->record_pk_cond($value));
35             }
36              
37             has 'req_Row', is => 'ro', lazy => 1, traits => [ 'RapidApp::Role::PerRequestBuildDefReset' ], default => sub {
38             #sub req_Row {
39             my $self = shift;
40             my $Rs = $self->_ResultSet;
41            
42             my $supId = $self->supplied_id;
43             die usererr "Record Id not supplied in request", title => 'Id not supplied'
44             unless (defined $supId || defined $self->c->req->params->{$self->_rst_qry_param});
45            
46             my $count = $Rs->count;
47            
48             unless ($count == 1) {
49             my $idErr = defined $supId ? "id: '$supId'" : "'" . $self->c->req->params->{$self->_rst_qry_param} . "'";
50              
51             die usererr 'Record not found by ' . $idErr, title => 'Record not found'
52             unless ($count);
53            
54             die usererr $count . ' records match ' . $idErr , title => 'Multiple records match';
55             }
56            
57             my $Row = $Rs->first or return undef;
58            
59             if ($self->getTabTitle) {
60             my $title = $self->getTabTitle->($self,$Row);
61             $self->apply_extconfig( tabTitle => $title ) if ($title);
62             }
63            
64             if ($self->getTabIconCls) {
65             my $iconCls = $self->getTabIconCls->($self,$Row);
66             $self->apply_extconfig( tabIconCls => $iconCls ) if ($iconCls);
67             }
68            
69             # New: honor/apply again the apply_extconfig (this was added as a quick fix
70             # for the case when we're redispatched from a rel rest path)
71             # TODO/FIXME: do this properly...
72             my $ovr = $self->c->stash->{apply_extconfig};
73             $self->apply_extconfig( %$ovr ) if ($ovr);
74            
75             return $Row;
76             };
77              
78              
79              
80             1;