view Lib/IMPL/Web/Application/RestBaseResource.pm @ 215:77a9934a44af

sync, migrating to XML::Compile
author cin
date Sun, 19 Aug 2012 22:27:43 +0400
parents c8fe3f84feba
children
line wrap: on
line source

package IMPL::Web::Application::RestBaseResource;
use strict;

use IMPL::lang qw(:declare :constants);
use IMPL::declare {
	require => {
		Exception => 'IMPL::Exception',
		ArgumentException => '-IMPL::InvalidArgumentException',
		NotImplException => '-IMPL::NotImplementedException',
		ForbiddenException => 'IMPL::Web::ForbiddenException',
		TTransform => '-IMPL::Transform'
	},
    base => {
        'IMPL::Object' => undef,
        'IMPL::Object::Autofill' => '@_'
    }
};


BEGIN {
    public property id => PROP_GET | PROP_OWNERSET;
    public property parent => PROP_GET | PROP_OWNERSET;
    public property contract => PROP_GET | PROP_OWNERSET;
    protected property final => PROP_ALL;
}

sub target {
	shift;
}

sub CTOR {
    my ($this) = @_;
    
    die ArgumentException->new("id","Identifier is required for non-root resources") if $this->id and not length $this->id;
    die ArgumentException->new("A contract is required") unless $this->contract;
}

sub GetHttpImpl {
    my($this,$method) = @_;
    
    my %map = (
        GET => 'GetImpl',
        PUT => 'PutImpl',
        POST => 'PostImpl',
        DELETE => 'DeleteImpl'
    );
    
    return $map{$method};
}

sub InvokeHttpMethod {
    my ($this,$method,$action) = @_;
    
    my $impl = $this->GetHttpImpl($method) || 'HttpFallbackImpl';
    
    return $this->$impl($action);
}

sub GetImpl {
	die NotImplException->new();
}

sub PutImpl {
    die NotImplException->new();
}

sub PostImpl {
    die NotImplException->new();
}

sub DeleteImpl {
    die NotImplException->new();
}

sub HttpFallbackImpl {
    die ForbiddenException->new();
}

sub FetchChildResource {
	return undef;
}


1;

__END__

=pod



=cut