annotate Lib/IMPL/Transform.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 94d47b388442
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package IMPL::Transform;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use base qw(IMPL::Object IMPL::Object::Autofill);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 protected _direct property Templates => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 protected _direct property Default => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 protected _direct property Plain => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 __PACKAGE__->PassThroughArgs;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 sub Transform {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 my ($this,$object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 if (not ref $object) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 die new IMPL::Exception("There is no the template for a plain value in the transform") unless $this->{$Plain};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 my $template = $this->{$Plain};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 return $this->$template($object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 my $template = $this->MatchTemplate($object) || $this->Default or die new IMPL::Transform::NoTransformException(ref $object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 return $this->$template($object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 sub MatchTemplate {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 my ($this,$object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 my $class = ref $object;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 foreach my $tClass ( keys %{$this->Templates || {}} ) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 return $this->Templates->{$tClass} if ($tClass eq $class);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 package IMPL::Transform::NoTransformException;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 use base qw(IMPL::Exception);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 1;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 __END__
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 =pod
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 =head1 SYNOPSIS
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 my $obj = new AnyObject;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 my $t = new Transform (
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 AnyClass => sub {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 my ($this,$object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 return new NewClass({ Name => $object->name, Document => $this->Transform($object->Data) })
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 },
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
56 DocClass => sub {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
57 my ($this,$object) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
58 return new DocPreview(Author => $object->Author, Text => $object->Data);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 );
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
61
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
62 =head1 Summary
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63 Ïðåîáðàçóåò äàííûå ñîäåðæàùèåñÿ â ôîðìå â ðåàëüíûå îáúåêòû èñïîëüçóÿ ñïåöèàëüíîå ïðåîáðàçîâàíèå.
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 =cut