comparison Lib/IMPL/Web/Application/ControllerUnit.pm @ 173:aaab45153411

minor bugfixes
author sourcer
date Wed, 14 Sep 2011 18:59:01 +0400
parents 068acfe903c3
children d1676be8afcc
comparison
equal deleted inserted replaced
172:068acfe903c3 173:aaab45153411
11 11
12 use constant { 12 use constant {
13 CONTROLLER_METHODS => 'controller_methods', 13 CONTROLLER_METHODS => 'controller_methods',
14 STATE_CORRECT => 'correct', 14 STATE_CORRECT => 'correct',
15 STATE_NEW => 'new', 15 STATE_NEW => 'new',
16 STATE_INVALID => 'invalid' 16 STATE_INVALID => 'invalid',
17 TTYPE_FORM => 'form',
18 TTYPE_TRANS => 'tran'
17 }; 19 };
18 20
19 BEGIN { 21 BEGIN {
20 public property action => prop_get | owner_set; 22 public property action => prop_get | owner_set;
21 public property application => prop_get | owner_set; 23 public property application => prop_get | owner_set;
56 $info = {}; 58 $info = {};
57 } 59 }
58 60
59 $info->{wrapper} = 'TransactionWrapper'; 61 $info->{wrapper} = 'TransactionWrapper';
60 $info->{method} ||= $method; 62 $info->{method} ||= $method;
63 $info->{context}{transactionType} = TTYPE_TRANS;
61 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; 64 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
62 } 65 }
63 } 66 }
64 67
65 sub forms { 68 sub forms {
69 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method); 72 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method);
70 if ( not ref $info ) { 73 if ( not ref $info ) {
71 $self->class_data(CONTROLLER_METHODS)->{$method} = { 74 $self->class_data(CONTROLLER_METHODS)->{$method} = {
72 wrapper => 'FormWrapper', 75 wrapper => 'FormWrapper',
73 schema => $info, 76 schema => $info,
74 method => $method 77 method => $method,
78 context => { transactionType => TTYPE_FORM }
75 }; 79 };
76 } elsif (ref $info eq 'HASH') { 80 } elsif (ref $info eq 'HASH') {
77 $info->{wrapper} = 'FormWrapper'; 81 $info->{wrapper} = 'FormWrapper';
78 $info->{method} ||= $method; 82 $info->{method} ||= $method;
83 $info->{context}{transactionType} = TTYPE_FORM;
79 84
80 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; 85 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
81 } else { 86 } else {
82 die new IMPL::Exception("Unsupported method information",$self,$method); 87 die new IMPL::Exception("Unsupported method information",$self,$method);
83 } 88 }
86 91
87 sub InvokeAction { 92 sub InvokeAction {
88 my ($self,$method,$action) = @_; 93 my ($self,$method,$action) = @_;
89 94
90 if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) { 95 if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) {
96 if (my $ctx = $methodInfo->{context}) {
97 $action->context->{$_} = $ctx->{$_} foreach keys %$ctx;
98 }
91 if (my $wrapper = $methodInfo->{wrapper}) { 99 if (my $wrapper = $methodInfo->{wrapper}) {
92 return $self->$wrapper($method,$action,$methodInfo); 100 return $self->$wrapper($method,$action,$methodInfo);
93 } else { 101 } else {
94 return $self->TransactionWrapper($method,$action,$methodInfo); 102 return $self->TransactionWrapper($method,$action,$methodInfo);
95 } 103 }