Advertisement
bvn13

Untitled

Feb 7th, 2013
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. package ASObjects::CatalogTest; {
  2.  
  3. use strict;
  4. use Moose;
  5.  
  6. use Data::Dumper;
  7.  
  8. use ASObjects::MValue;
  9. #use ASObjects::MAttributes;
  10. use DB::_Generator;
  11.  
  12. sub BUILD {
  13. my $self = shift;
  14. print "ASObjects::Catalog->BUILD\n";
  15. my $attrs = [qw/attr1 attr2 attr3/];
  16.  
  17. for my $aname (@$attrs) {
  18. print "adding attr $aname\n";
  19. # $self->attrs->{$aname} = ASObjects::MValue->new;
  20. has $aname => (
  21. is => 'rw',
  22. isa => 'Any'
  23. );
  24. }
  25. #print Dumper $attrs;
  26. # считаем табличные части
  27. };
  28.  
  29. use overload
  30. '""' => sub {
  31. my $self = shift;
  32. my $n = $self->attrs->{name}->value;
  33. my $c = $self->attrs->{code}->value;
  34. "$n ($c)";
  35. };
  36.  
  37. has '_attrsFromDB' => (
  38. is => 'rw',
  39. isa => 'Any',
  40. init_arg => undef, # нельзя задать в конструкторе
  41. );
  42.  
  43. has '_dummy' => (
  44. is => 'rw',
  45. isa => 'Any',
  46. init_arg => undef,
  47. #builder => 'init',
  48. #lazy => 1,
  49. );
  50.  
  51. has '_type' => (
  52. is => 'ro',
  53. isa => 'Str',
  54. required => '1',
  55. default => sub { confess "ASSERT! " . __PACKAGE__ . " : Type is not setted!\n"; }
  56. );
  57.  
  58. has '_dbClassName' => (
  59. is => 'rw',
  60. isa => 'Str',
  61. );
  62.  
  63. has 'attrs' => (
  64. is => 'rw',
  65. isa => 'HashRef[ASObjects::MValue]',
  66. default => sub { {} },
  67. );
  68.  
  69. has 'tables' => (
  70. is => 'rw',
  71. isa => 'HashRef[ArrayRef[HashRef[ASObjects::MValue]]]',
  72. default => sub { {} },
  73. );
  74.  
  75. sub get_attr {
  76. my ($self, $aname) = @_;
  77. return $self->attrs->{$aname};
  78. };
  79.  
  80. sub set_attr {
  81. my ($self, $aname, $aval) = @_;
  82. confess "ASSERT! " . __PACKAGE__ . " : Attribute <$aname> does not exist!\n" if !defined $self->attrs->{$aname};
  83.  
  84. $self->attrs->{$aname} = $aval;
  85. };
  86.  
  87. sub init {
  88. my $self = shift;
  89. for my $aname (@{$self->_attrsFromDB}) {
  90. print "adding attr $aname\n";
  91. $self->attrs->{$aname} = ASObjects::MValue->new;
  92. has $aname => (
  93. is => 'rw',
  94. isa => 'Any'
  95. );
  96. }
  97. return $self;
  98. };
  99.  
  100. };
  101.  
  102. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement