diff Lib/IMPL/Web/Application/Resource.pm @ 335:e8be9062ecf2

improved resource classes, contracts are deprecated
author cin
date Thu, 13 Jun 2013 20:13:24 +0400
parents 71221d79e6b4
children ec58c47edb52
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/Resource.pm	Thu Jun 13 02:24:57 2013 +0400
+++ b/Lib/IMPL/Web/Application/Resource.pm	Thu Jun 13 20:13:24 2013 +0400
@@ -13,7 +13,8 @@
 		OperationException  => '-IMPL::InvalidOperationException',
 		NotAllowedException => 'IMPL::Web::NotAllowedException',
 		NotFoundException   => 'IMPL::Web::NotFoundException',
-		Loader              => 'IMPL::Code::Loader' 
+		Loader              => 'IMPL::Code::Loader',
+		CustomResource      => '-IMPL::Web::Application::CustomResource' 
 	  },
 	  base => [
 		'IMPL::Object'                              => undef,
@@ -26,10 +27,6 @@
 		model       => PROP_RO,
 		id          => PROP_RO,
 		location    => PROP_RO,
-		resources   => PROP_RO,
-		verbs       => PROP_RO,
-		namedResources => PROP_RO,
-		regexResources => PROP_RO
 	  ]
 };
 
@@ -48,45 +45,20 @@
 	$this->model( $args{model} );
 	$this->id( $args{id} );
 	$this->application( $args{request}->application );
-	$this->verbs( $args{verbs} || {} );
-	$this->resources($args{resources} || []);
 	
-	$this->PrepareResourcesCache();
-
 # если расположение явно не указано, то оно вычисляется автоматически,
 # либо остается не заданным
 	$this->location( $args{location}
 		  || eval { $this->parent->location->Child( $this->id ) } );
 }
 
-sub PrepareResourcesCache {
-    my ($this,$resources) = @_;
-    my %nameMap;
-    my @rxMap;
-
-    foreach my $res (@{$this->resources}) {
-        #skip resources without contract
-        next unless $res->{contract};
-        
-        if ( my $name = $res->{name} ) {
-            $nameMap{$name} = $res;
-        }
-        if ( $res->{match} ) {
-            push @rxMap,$res;
-        }
-    }
-
-    $this->regexResources(\@rxMap);
-    $this->namedResources(\%nameMap);
-}
-
 sub InvokeHttpVerb {
 	my ( $this, $verb ) = @_;
 
 	my $operation = $this->verbs->{ lc($verb) };
 
 	die NotAllowedException->new(
-		allow => join( ',', map( uc, keys %{ $this->verbs } ) ) )
+		allow => join( ',', $this->GetAllowedMethods ) )
 	  unless $operation;
 
 	$this->AccessCheck($verb);
@@ -110,6 +82,14 @@
 	return _InvokeDelegate( $operation, $this, $request );
 }
 
+sub GetAllowedMethods {
+	
+}
+
+sub FindChildResourceInfo {
+	
+}
+
 sub AccessCheck {
 
 }
@@ -129,24 +109,6 @@
 	return $env;
 }
 
-sub FindChildResourceInfo {
-    my ( $this, $name ) = @_;
-    
-    if ( my $info = $this->namedResources->{$name} ) {
-        return $info, [$name];
-    }
-    else {
-        foreach my $info ( @{$this->regexResources} ) {
-            my $rx = $info->{match};
-            if(my @childId = $name =~ m/$rx/) {
-                return $info, \@childId; 
-            }
-        }
-    }
-
-    return;
-}
-
 # это реализация по умолчанию, базируется информации о ресурсах, содержащийся
 # в контракте.
 sub FetchChildResource {
@@ -186,7 +148,7 @@
 	my $factory;
 	
 	if (ref($contract) eq 'HASH') {
-	    $factory = delete $contract->{class} || __PACKAGE__;
+	    $factory = delete $contract->{class} || CustomResource;
 	    hashApply(\%args,$contract);
 	    
 	    Loader->default->Require($factory)