diff Lib/IMPL/Web/View/Metadata/ObjectProvider.pm @ 362:715b9959b207

WebView: initial work on metadata providers
author cin
date Thu, 28 Nov 2013 20:00:20 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Web/View/Metadata/ObjectProvider.pm	Thu Nov 28 20:00:20 2013 +0400
@@ -0,0 +1,48 @@
+package IMPL::Web::View::Metadata::ObjectProvider;
+use strict;
+
+use IMPL::lang;
+use IMPL::declare {
+	require => {
+		Exception => 'IMPL::Exception',
+		ArgException => '-IMPL::InvalidArgumentException',
+		Meta => 'IMPL::Web::View::Metadata',
+		PropertyInfo => 'IMPL::Class::PropertyInfo'
+	},
+	base => [
+		'IMPL::Object' => undef
+	]
+};
+
+sub GetMetadata {
+	my ($this,$model) = @_;
+	
+	my $class = typeof($model) || $model;
+		
+	return Meta->new(
+		type => $class,
+		provider => $this
+	);
+}
+
+# returns array of metadata
+sub GetFields {
+	my ($this,$class) = @_;
+	
+	my %seen;
+	
+	return map {
+		my %meta = (
+			provider => $this
+		);
+		
+		$meta{type} = $_->type if $_->type;
+		
+		# TODO extend from metadata and external providers
+		
+		return Meta->new(%meta);
+	} $class->GetMeta(PropertyInfo, sub { $seen{$_->name} ? 0 : ($seen{$_->name} = 1) } , 1); 
+	
+}
+
+1;
\ No newline at end of file