362
|
1 package IMPL::Web::View::Metadata::ObjectProvider;
|
|
2 use strict;
|
|
3
|
|
4 use IMPL::lang;
|
|
5 use IMPL::declare {
|
|
6 require => {
|
|
7 Exception => 'IMPL::Exception',
|
|
8 ArgException => '-IMPL::InvalidArgumentException',
|
|
9 Meta => 'IMPL::Web::View::Metadata',
|
|
10 PropertyInfo => 'IMPL::Class::PropertyInfo'
|
|
11 },
|
|
12 base => [
|
|
13 'IMPL::Object' => undef
|
|
14 ]
|
|
15 };
|
|
16
|
|
17 sub GetMetadata {
|
|
18 my ($this,$model) = @_;
|
|
19
|
|
20 my $class = typeof($model) || $model;
|
|
21
|
|
22 return Meta->new(
|
|
23 type => $class,
|
|
24 provider => $this
|
|
25 );
|
|
26 }
|
|
27
|
|
28 # returns array of metadata
|
|
29 sub GetFields {
|
|
30 my ($this,$class) = @_;
|
|
31
|
|
32 my %seen;
|
|
33
|
|
34 return map {
|
|
35 my %meta = (
|
|
36 provider => $this
|
|
37 );
|
|
38
|
|
39 $meta{type} = $_->type if $_->type;
|
|
40
|
|
41 # TODO extend from metadata and external providers
|
|
42
|
|
43 return Meta->new(%meta);
|
|
44 } $class->GetMeta(PropertyInfo, sub { $seen{$_->name} ? 0 : ($seen{$_->name} = 1) } , 1);
|
|
45
|
|
46 }
|
|
47
|
|
48 1; |