diff lib/IMPL/Config/ServicesBag.pm @ 411:ee36115f6a34 ref20150831

sync
author cin
date Mon, 21 Sep 2015 00:53:10 +0300
parents c6e90e02dd17
children
line wrap: on
line diff
--- a/lib/IMPL/Config/ServicesBag.pm	Mon Sep 14 01:11:53 2015 +0300
+++ b/lib/IMPL/Config/ServicesBag.pm	Mon Sep 21 00:53:10 2015 +0300
@@ -6,6 +6,9 @@
 
 use IMPL::Const qw(:prop);
 use IMPL::declare {
+	require => {
+		Entry => '-IMPL::Config::ServicesBag::Entry'
+	},
 	base => [
 		'IMPL::Object' => undef
 	],
@@ -57,7 +60,7 @@
 sub RegisterValue {
 	my ( $this, $value, $name, $type ) = @_;
 
-	my $d = { owner => $this, value => $value, valid => 1 };
+	my $d = Entry->new( {owner => $this, value => $value} );
 
 	if ($type) {
 		my $map = $this->_typeMap;
@@ -77,32 +80,25 @@
 			$map->{$t} = $d;
 		}
 
-		if ($replaces) {
-
 			# invalidate cache
-			$replaces->{owner}->UpdateDescriptor($replaces);
-		}
+			$replaces->Invalidate() if $replaces;
+		
 	}
 
 	if ($name) {
 		my $prev = $this->_nameMap->{$name};
 		$d->{name} = $name;
 		$this->_nameMap->{$name} = $d;
-		$prev->{owner}->UpdateDescriptor($prev) if $prev;
+		$prev->Invalidate() if $prev;
 	}
 
 	return $d;
 }
 
-sub UpdateDescriptor {
+sub _UpdateDescriptor {
 	my ( $this, $d ) = @_;
 
-	my $d2 = {};
-
-	# copy descriptor
-	while ( my ( $k, $v ) = each %$d ) {
-		$d2->{$k} = $v;
-	}
+	my $d2 = Entry->new($d);
 
 	# update named entries
 	my $name = $d->{name};
@@ -122,6 +118,33 @@
 	$d->{valid} = 0;
 }
 
+package IMPL::Config::ServicesBag::Entry;
+use IMPL::Exception();
+use IMPL::declare {
+	base => [
+	   'IMPL::Object::Fields' => undef
+	]
+};
+
+my @fields = qw(owner type isa valid value); 
+use fields @fields;
+
+sub CTOR {
+	my SELF $this = shift;
+	my $args = shift;
+	
+	$this->{valid} = 1;
+	$this->{owner} = $args{owner} or die IMPL::InvalidArgumentException->new("owner");
+	$this->{value} = $args{value} if exists $args->{value};
+	$this->{isa} = $args{isa} if $args->{isa};
+}
+
+sub Invalidate {
+	my SELF $this = shift;
+	
+	$this->{owner}->_UpdateDescriptor($this);
+}
+
 1;
 
 __END__