Mercurial > pub > Impl
comparison Lib/IMPL/Transform.pm @ 38:d660fb38b7cc
small fixes
ORM shema to SQL schema transformation
| author | Sergey |
|---|---|
| date | Mon, 23 Nov 2009 17:57:07 +0300 |
| parents | 94d47b388442 |
| children | 32d2350fccf9 |
comparison
equal
deleted
inserted
replaced
| 37:c2e7f7c96bcd | 38:d660fb38b7cc |
|---|---|
| 18 | 18 |
| 19 $this->{$Templates} = \%args; | 19 $this->{$Templates} = \%args; |
| 20 } | 20 } |
| 21 | 21 |
| 22 sub Transform { | 22 sub Transform { |
| 23 my ($this,$object) = @_; | 23 my ($this,$object,@args) = @_; |
| 24 | 24 |
| 25 if (not ref $object) { | 25 if (not ref $object) { |
| 26 die new IMPL::Exception("There is no the template for a plain value in the transform") unless $this->{$Plain}; | 26 die new IMPL::Exception("There is no the template for a plain value in the transform") unless $this->{$Plain}; |
| 27 my $template = $this->{$Plain}; | 27 my $template = $this->{$Plain}; |
| 28 return $this->$template($object); | 28 return $this->$template($object,@args); |
| 29 } else { | 29 } else { |
| 30 | 30 |
| 31 my $template = $this->MatchTemplate($object) || $this->Default or die new IMPL::Transform::NoTransformException(ref $object); | 31 my $template = $this->MatchTemplate($object) || $this->Default or die new IMPL::Transform::NoTransformException(ref $object); |
| 32 | 32 |
| 33 return $this->$template($object); | 33 return $this->$template($object,@args); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 sub MatchTemplate { | 37 sub MatchTemplate { |
| 38 my ($this,$object) = @_; | 38 my ($this,$object) = @_; |
| 39 my $class = ref $object; | 39 my $class = $this->GetClassForObject( $object ); |
| 40 | 40 |
| 41 foreach my $tClass ( keys %{$this->Templates || {}} ) { | 41 foreach my $tClass ( keys %{$this->Templates || {}} ) { |
| 42 return $this->Templates->{$tClass} if ($tClass eq $class); | 42 return $this->Templates->{$tClass} if ($tClass eq $class); |
| 43 } | 43 } |
| 44 } | |
| 45 | |
| 46 sub GetClassForObject { | |
| 47 my ($this,$object) = @_; | |
| 48 | |
| 49 return ref $object; | |
| 44 } | 50 } |
| 45 | 51 |
| 46 package IMPL::Transform::NoTransformException; | 52 package IMPL::Transform::NoTransformException; |
| 47 use base qw(IMPL::Exception); | 53 use base qw(IMPL::Exception); |
| 48 | 54 |
| 74 } | 80 } |
| 75 ); | 81 ); |
| 76 | 82 |
| 77 my $result = $t->Transform($obj); | 83 my $result = $t->Transform($obj); |
| 78 | 84 |
| 79 =head1 Summary | 85 =head1 DESCRIPTION |
| 80 Преобразует данные содержащиеся в форме в реальные объекты используя специальное преобразование. | 86 |
| 87 Преобразование одного объекта к другому, например даных к их представлению. | |
| 81 | 88 |
| 82 =cut | 89 =cut |
