diff lib/IMPL/Config/Descriptor.pm @ 415:3d24b10dd0d5 ref20150831

working on IMPL::Config::Container
author cin
date Tue, 20 Oct 2015 07:32:55 +0300
parents af8d359ee4cc
children df591e3afd10
line wrap: on
line diff
--- a/lib/IMPL/Config/Descriptor.pm	Fri Oct 02 06:56:24 2015 +0300
+++ b/lib/IMPL/Config/Descriptor.pm	Tue Oct 20 07:32:55 2015 +0300
@@ -1,12 +1,46 @@
 package IMPL::Config::Descriptor;
 use strict;
 use IMPL::Exception();
+use Scalar::Util qw(looks_like_number);
+
+sub ACTIVATE_SINGLETON() { 1 }
+sub ACTIVATE_CONTAINER() { 2 }
+sub ACTIVATE_CONTEXT()   { 3 }
+sub ACTIVATE_CALL()      { 4 }
+
+my %activateNames = (
+	singleton => ACTIVATE_SINGLETON,
+	container => ACTIVATE_CONTAINER,
+	context   => ACTIVATE_CONTEXT,
+	call      => ACTIVATE_CALL
+);
+
+my %activateNamesLookup = map { $activateNames{$_}, $_ } keys %activateNames;
 
 sub Activate {
-	my ($this, $context) = @_;
+	my ( $this, $context ) = @_;
 	die IMPL::NotImplementedException->new();
 }
 
+sub ParseActivation {
+	my $val = pop @_;
+
+	return ACTIVATE_CALL unless $val;
+
+	return grep $_ == $val,
+	  ACTIVATE_SINGLETON,
+	  ACTIVATE_CONTAINER,
+	  ACTIVATE_CONTEXT, ACTIVATE_CALL ? $val : ACTIVATE_CALL
+	  if looks_like_number($val);
+
+	return $activateNames{ lc($val) } || ACTIVATE_CALL;
+}
+
+sub ActivationToString {
+	my $val = pop @_;
+
+	return ( $val && $activateNamesLookup{$val} ) || '';
+}
 
 1;
 
@@ -54,4 +88,4 @@
 
 =back
 
-=cut
\ No newline at end of file
+=cut