view Lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 368:010ceafd0c5a

form metadata + tests
author cin
date Wed, 04 Dec 2013 17:31:53 +0400
parents 608e74bc309f
children
line wrap: on
line source

package IMPL::Web::View::Metadata::BaseMeta;
use strict;

use IMPL::lang;
use IMPL::Const qw(:prop);
use IMPL::declare {
	require => {
		Exception => 'IMPL::Exception',
		ArgException => '-IMPL::InvalidArgumentException',
		NotImplException => '-IMPL::NotImplementedException'
	},
	base => [
		'IMPL::Object' => undef
	],
	props => [
		model => PROP_RO,
		modelType => PROP_RO,
		name => PROP_RO,
		label => PROP_RO,
		container => PROP_RO,
		template => PROP_RO,
		
		_childMap => PROP_RO,
		_childNames => PROP_RO
	]
};

sub CTOR {
	my ($this,$model,$type,$args) = @_;
	
	$this->model($model);
	$this->modelType($type);
	$this->_childMap({});
	
	#mixin other args
	if ($args) {
		$this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template);
	}
}

sub GetProperty {
	my ($this,$name) = @_;
	
	$this->GetProperties()
		unless $this->_childNames;
	
	return $this->_childMap->{$name};
}

sub GetProperties {
	my ($this) = @_;
	
	if ($this->_childNames) {
		return [ map $this->_childMap->{$_}, @{$this->_childNames} ];
	} else {
		my @childNames;
		my %childMap;
		my @result; 
	
		foreach my $child (@{$this->PopulateProperties()}) {
			$childMap{$child->name} = $child;
			push @childNames, $child->name;
			push @result, $child;
		}
		
		$this->_childMap(\%childMap);
		$this->_childNames(\@childNames);
		return \@result;
	}	
}

sub PopulateProperties {
	my ($this) = @_;
	
	die NotImplException->new();
}

sub GetItems {
	my ($this) = @_;
	
	die NotImplException->new();
}

sub GetItem {
	my ($this,$index) = @_;
	
	die NotImplException->new();
}

1;

__END__

=pod

=head1 NAME

=head1 SYNOPSIS

=head1 DESCRIPTION

Метаданные описывают модель, ее свойства, используются для построения
представления.

=over

=item * type

Опционально. Тип модели. В случаях, когда модель не определена, данное свойство
позволяет определить ее тип.

=item * label

Опционально. Имя модели для отображения.

=item * template

Шаблон, который следует использовать для отображения модели.

=item * fields

Коллекция с информацией по свойствам (полям) модели. Данный хеш используется
для определения представления при использовании C<display_for('field')>.

=back

Метаданные публикуются провайдером, кроме того они могут быть расширены
дополнительными свойствами.

=head1 MEMBERS

=head2 C<GetChild($name)>

Возвращает метаданные для дочернего элемента, например свойства объекта

=head2 C<GetChildren()>

Возвращает ссылку на массив с метаданными для дочерних элементов

=cut