view Lib/IMPL/Web/RestContract.pm @ 199:e743a8481327

Added REST support for forms (with only get and post methods)
author sergey
date Mon, 23 Apr 2012 01:36:52 +0400
parents 2ffe6f661605
children a9dbe534d236
line wrap: on
line source

package IMPL::Web::RestContract;
use strict;

use IMPL::lang qw(:declare :constants);
use IMPL::declare {
	require => {
		Exception => 'IMPL::Exception',
		InvalidOpException => '-IMPL::InvalidOperationException',
		ForbiddenException => 'IMPL::Web::ForbiddenException',
		TRestResource => 'IMPL::Web::Application::RestResource',
	},
	base => {
		'IMPL::Transform' => sub { my %args = @_; $args{resources} },
		'IMPL::Object::Serializable' => undef
	}
};

sub CTOR {
	my ($this) = @_;
	
	$this->templates->{-plain} = sub { die ForbiddenException->new(); };
	$this->templates->{-default} = sub { die ForbiddenException->new(); };
	$this->templates->{TRestResource} = sub { $_[0] };
}

sub ProcessTemplate {
	my ($this,$t,$obj,$props) = @_;
	
	$props ||= {};
	
	if (ref $t eq 'HASH') {
		my $factory = $t->{factory} || TRestResource;
		return $factory->new(%$t, target => $obj, %$props);
	} elsif (ref $t eq 'CODE') {
		return $this->$t($obj,$props);
	} else {
		die InvalidOpException->new();
	}
}



1;

__END__

=pod

=head1 NAME

C<IMPL::Web::RestContract> Описывает правила публикации ресурсов.

=head1 SYNOPSIS

=begin code

=end code 

=cut