diff Lib/IMPL/DOM/Schema/Label.pm @ 381:ced5937ff21a

Custom getters/setters support method names in theirs definitions Initial support for localizable labels in DOM schemas
author cin
date Wed, 22 Jan 2014 16:56:10 +0400
parents
children 2f16f13b000c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/DOM/Schema/Label.pm	Wed Jan 22 16:56:10 2014 +0400
@@ -0,0 +1,48 @@
+package IMPL::DOM::Schema::Label;
+use strict;
+use overload
+	'""' => 'ToString',
+    'bool'     =>   sub { return 1; },
+    'fallback' => 1;
+
+use IMPL::Const qw(:prop);
+use IMPL::Exception();
+use IMPL::declare {
+	require => {
+		ArgException => '-IMPL::InvalidArgumentException'
+	},
+	base => [
+		'IMPL::Object' => undef
+	],
+	props => [
+		_map => PROP_RW,
+		_id => PROP_RW
+	]
+};
+
+sub CTOR {
+	my ($this,$map,$id) = @_;
+	
+	die ArgException->new('map' => 'A strings map is required')
+		unless $map;
+	die ArgException->new('id' => 'A lable identifier is required')
+		unless $id;
+}
+
+our $AUTOLOAD;
+sub AUTOLOAD {
+	my ($this) = @_;
+	
+	my ($method) = ($AUTOLOAD =~ /(\w+)$/);
+	return
+		if $method eq 'DESTROY';
+		
+	return $this->new($this->_map,$method);
+}
+
+sub ToString {
+	my ($this) = @_;
+	return $this->_map->GetString($this->_id);
+}
+
+1;
\ No newline at end of file