Mercurial > pub > Impl
changeset 111:6c25ea91c985
ControllerUnit concept
author | wizard |
---|---|
date | Tue, 18 May 2010 01:33:37 +0400 (2010-05-17) |
parents | c13a215508ca |
children | 0ed8e2541b1c |
files | Lib/IMPL/Class/Meta.pm Lib/IMPL/Web/Application/ControllerUnit.pm |
diffstat | 2 files changed, 163 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Class/Meta.pm Mon May 17 17:42:27 2010 +0400 +++ b/Lib/IMPL/Class/Meta.pm Tue May 18 01:33:37 2010 +0400 @@ -200,7 +200,7 @@ sub say_version { my ($self) = @_; - print $self->class_data(info)->{version}; + print $self->class_data('info')->{version}; } package Bar;
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm Mon May 17 17:42:27 2010 +0400 +++ b/Lib/IMPL/Web/Application/ControllerUnit.pm Tue May 18 01:33:37 2010 +0400 @@ -8,6 +8,9 @@ public property action => prop_get | owner_set; public property application => prop_get | owner_set; public property query => prop_get | owner_set; + public property formData => prop_get | owner_set; + public property formSchema => prop_get | owner_set; + public property formErrors => prop_get | owner_set; } sub CTOR { @@ -27,4 +30,162 @@ } else { die new IMPL::InvalidOperationException("Invalid method call",$self,$method); } -} \ No newline at end of file +} + +1; + +__END__ + +=pod + +=head1 NAME + +C<IMPL::Web::Application::ControllerUnit> - ������� ����� ��� ����������� ���������� � ������ �����������. + +=head1 DESCRIPTION + +������, ����������� �� ������� ������ ������������ ��� ���������� ����������, ������� �������� +����� ���������� ��������. ��� ������� ���� ����� ������������ ����� ����� ����������, ������ +�� ������� �������� ����������� �� ������. + +����� ����������� ���������� ��������� ��������� �������, � ������ �������� ����� ��������� ����������. +��� ����� ���������� ����� C<InvokeAction($method,$action)>, ������� �������/��������������� �������� +����������. + +���������� �� ������ ������ ������� �� ������� � �����. + +=head2 ������� ���������� + +������� ���������� ������� ������ ������, ��� ��������������� ���������, � ������������ ��������� �������� +���������� ������������. + +=head2 ����� + +��� ������������� ���� ������ �������������� ��������������, ��� ��������� DOM ��������� � ������� �����. +��� ������������ DOM ��������� ������������ �����. ��� ���� ���������� �������� �������������� �������� +C<formData>, C<formSchema>, C<formErrors>. + +��������� ���������� ���������� �� ������������ �������� ������������, � ���������� � ����� �����, ������� +�������� ��������� ������� + +=begin code + +{ + state => '{ new | correct | invalid }', + result => $transactionResult, + formData => $formDOM, + formSchema => $formSchema, + formErrors => @errors +} + +=end code + +=over + +=item C<state> + +��������� ����������� �����. + +=over + +=item C<new> + +�������������� ���������� �����, ��� ����� ���� ������������, �� ��� ���������. +� ������ ��������� ���������� ������ �� �����������. + +=item C<correct> + +������ ����� ���������, ���������� ���������, � �� ��������� �������� ����� ���� C<result> + +=item C<invalid> + +���������� ����� �� ������ �����������, ������ �������� ����� ���� C<formErrors>. ���������� +�� �����������. + +=back + +=item C<result> + +��������� ���������� ����������, ���� ������� ������� �����������. + +=item C<formData> + +��� �������� � ������� �������. �������� ���������� ������, �� �������� �� ��� ������������, +����� ���� ����������� ��� ���������� �����, ��� ����������� �����������. + +=item C<formSchema> + +����� ������ �����, ����� �������������� ��� ���������� ������������ ����. + +=item C<formErrors> + +������ ����������� ������, ���� ������� ���� + +=back + +=head1 MEMBERS + +=over + +=item C<[get] application> + +=item C<[get] query> + +=item C<[get] response> + +=item C<[get] formData> + +=item C<[get] formSchema> + +=item C<[get] formErrors> + +=item C<InvokeAction($method,$action)> + +������������ �������� ���������� ����������, ����� ���� ������������� ��� ��������������� ��������� �� +�������������. + +=back + +=head1 EXAMPLE + +=begin code + +package MyBooksUnit; +use strict; +use base qw(IMPL::Web::Application::ControllerUnit); + +__PACKAGE__->PassThroughArgs; + +__PACKAGE__->transactions(qw( + find + info +)); +__PACKAGE__->forms( + create => 'books.create.xml' +); + +sub find { + my ($this) = @_; + + return $this->application->dataSource->resultset('Books')->find({author => $this->query->param('author')}); +} + +sub info { + my ($this) = @_; + + return $this->application->dataSource->resultset('Books')->find({id => $this->query->param('id')}); +} + +sub create { + my ($this) = @_; + + my %book = map { + $_ => $this->formData->selectSingleNode($_)->nodeValue + } qw(author_id title year ISBN); + + return $this->application->datasource->resultset('Books')->create(\%book); +} + +=end code + +=cut \ No newline at end of file