view Lib/IMPL/Web/RestContract.pm @ 205:891c04080658

IMPL::Web::View fixed template selection, release candidate
author sergey
date Thu, 03 May 2012 01:00:02 +0400
parents a9dbe534d236
children 292226770180
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, contract => $this, %$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