Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ASObjects::CatalogTest; {
- use strict;
- use Moose;
- use Data::Dumper;
- use ASObjects::MValue;
- #use ASObjects::MAttributes;
- use DB::_Generator;
- sub BUILD {
- my $self = shift;
- print "ASObjects::Catalog->BUILD\n";
- my $attrs = [qw/attr1 attr2 attr3/];
- for my $aname (@$attrs) {
- print "adding attr $aname\n";
- # $self->attrs->{$aname} = ASObjects::MValue->new;
- has $aname => (
- is => 'rw',
- isa => 'Any'
- );
- }
- #print Dumper $attrs;
- # считаем табличные части
- };
- use overload
- '""' => sub {
- my $self = shift;
- my $n = $self->attrs->{name}->value;
- my $c = $self->attrs->{code}->value;
- "$n ($c)";
- };
- has '_attrsFromDB' => (
- is => 'rw',
- isa => 'Any',
- init_arg => undef, # нельзя задать в конструкторе
- );
- has '_dummy' => (
- is => 'rw',
- isa => 'Any',
- init_arg => undef,
- #builder => 'init',
- #lazy => 1,
- );
- has '_type' => (
- is => 'ro',
- isa => 'Str',
- required => '1',
- default => sub { confess "ASSERT! " . __PACKAGE__ . " : Type is not setted!\n"; }
- );
- has '_dbClassName' => (
- is => 'rw',
- isa => 'Str',
- );
- has 'attrs' => (
- is => 'rw',
- isa => 'HashRef[ASObjects::MValue]',
- default => sub { {} },
- );
- has 'tables' => (
- is => 'rw',
- isa => 'HashRef[ArrayRef[HashRef[ASObjects::MValue]]]',
- default => sub { {} },
- );
- sub get_attr {
- my ($self, $aname) = @_;
- return $self->attrs->{$aname};
- };
- sub set_attr {
- my ($self, $aname, $aval) = @_;
- confess "ASSERT! " . __PACKAGE__ . " : Attribute <$aname> does not exist!\n" if !defined $self->attrs->{$aname};
- $self->attrs->{$aname} = $aval;
- };
- sub init {
- my $self = shift;
- for my $aname (@{$self->_attrsFromDB}) {
- print "adding attr $aname\n";
- $self->attrs->{$aname} = ASObjects::MValue->new;
- has $aname => (
- is => 'rw',
- isa => 'Any'
- );
- }
- return $self;
- };
- };
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement