view Lib/IMPL/Web/RestContract.pm @ 200:a9dbe534d236

sync
author sergey
date Tue, 24 Apr 2012 02:34:49 +0400
parents e743a8481327
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