line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Author: Murat Uenalan (muenalan@cpan.org)
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# Copyright (c) 2001 Murat Uenalan. All rights reserved.
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
# Note: This program is free software; you can redistribute
|
6
|
|
|
|
|
|
|
#
|
7
|
|
|
|
|
|
|
# it and/or modify it under the same terms as Perl itself.
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Class::Maker::Extension::Schema::Tangram;
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6789
|
require 5.005_62; use strict; use warnings;
|
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Exporter;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
449
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01_01';
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(schema) ] );
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw();
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $mappings =
|
26
|
|
|
|
|
|
|
{
|
27
|
|
|
|
|
|
|
ARRAY =>
|
28
|
|
|
|
|
|
|
{
|
29
|
|
|
|
|
|
|
hash => 'flat_hash',
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
array => 'flat_array',
|
32
|
|
|
|
|
|
|
}
|
33
|
|
|
|
|
|
|
};
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _map_to_tangram
|
36
|
|
|
|
|
|
|
{
|
37
|
0
|
|
|
0
|
|
|
my $attribs = shift;
|
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $mapping = shift;
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
foreach my $type ( keys %$attribs )
|
42
|
|
|
|
|
|
|
{
|
43
|
0
|
0
|
|
|
|
|
if( my $what = $mappings->{ ref $attribs->{$type} }->{$type} )
|
44
|
|
|
|
|
|
|
{
|
45
|
0
|
|
|
|
|
|
$attribs->{ $what } = $attribs->{ $type };
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
delete $attribs->{ $type };
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
}
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $attribs;
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Preloaded methods go here.
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our $classname_separator = '_';
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub schema
|
59
|
|
|
|
|
|
|
{
|
60
|
0
|
|
|
0
|
0
|
|
my %schema = ();
|
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
print "Gathering schema: ";
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $this ( @_ )
|
65
|
|
|
|
|
|
|
{
|
66
|
0
|
|
|
|
|
|
print "$this..\n";
|
67
|
|
|
|
|
|
|
|
68
|
0
|
|
0
|
|
|
|
foreach my $class ( @{Class::Maker::Reflection::inheritance_isa( ref($this) || $this )} )
|
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{
|
70
|
|
|
|
|
|
|
# main:: and :: prefix should be stripped from package identifier
|
71
|
|
|
|
|
|
|
#
|
72
|
|
|
|
|
|
|
# because of a bug in bless
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$class =~ s/^(?:main)?:://;
|
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
print "\tbase $class detected\n" if $Class::Maker::DEBUG;
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# inefficient PROVISIONAL because below i tweak in the original CLASS info, instead of doing
|
79
|
|
|
|
|
|
|
# it in the schema => but NOW i have not the time...
|
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my %copy = %{ Class::Maker::Reflection::reflect( $class )->definition };
|
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
print "DUMPER: ";
|
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
1
|
|
1188
|
use Data::Dumper;
|
|
1
|
|
|
|
|
12211
|
|
|
1
|
|
|
|
|
479
|
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
print Dumper \%copy;
|
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $reflex = \%copy;
|
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $cfg = $reflex->{persistance};
|
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
next if exists $cfg->{ignore};
|
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if( exists $cfg->{table} )
|
96
|
|
|
|
|
|
|
{
|
97
|
0
|
|
|
|
|
|
$schema{$class}->{table} = $cfg->{table};
|
98
|
|
|
|
|
|
|
}
|
99
|
0
|
|
|
|
|
|
elsif( 0 ) # $class =~ /::/ ) # because :: may conflict SQL
|
100
|
|
|
|
|
|
|
{
|
101
|
|
|
|
|
|
|
$schema{$class}->{table} = $class;
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$schema{$class}->{table} =~ s/::/$classname_separator/g;
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if( exists $cfg->{abstract} )
|
107
|
|
|
|
|
|
|
{
|
108
|
0
|
0
|
|
|
|
|
$schema{$class}->{abstract} = $cfg->{abstract} if exists $cfg->{abstract};
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
else
|
111
|
|
|
|
|
|
|
{
|
112
|
|
|
|
|
|
|
# Translate fieldnames to tangram types (see above for Tangram Type Extension Modules 'use')
|
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
foreach my $csection ( qw(public private protected) )
|
115
|
|
|
|
|
|
|
{
|
116
|
|
|
|
|
|
|
# look if we had a: type => [qw(eins zwei)] ...or... type => { eins => 'Object::Eins', ...
|
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
_map_to_tangram( $reflex->{$csection}, $mappings ) if exists $reflex->{$csection};
|
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
$schema{$class}->{fields} = $reflex->{$csection} if exists $reflex->{$csection};
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# look into array and ref fields for classes to be included into the schema
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
foreach my $obj_field ( qw(array ref) )
|
125
|
|
|
|
|
|
|
{
|
126
|
0
|
0
|
|
|
|
|
if( ref( $reflex->{$csection}->{$obj_field} ) eq 'HASH' )
|
127
|
|
|
|
|
|
|
{
|
128
|
|
|
|
|
|
|
# cylce to the references classes and if not already in schema -> add it..
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
foreach ( values %{ $reflex->{$csection}->{$obj_field} } )
|
|
0
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
{
|
132
|
0
|
0
|
|
|
|
|
unless( exists $schema{ $_ } )
|
133
|
|
|
|
|
|
|
{
|
134
|
|
|
|
|
|
|
# catch schema of referenced classes
|
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my %classes = @{ schema( $_ ) };
|
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
foreach my $class_key ( keys %classes )
|
139
|
|
|
|
|
|
|
{
|
140
|
0
|
|
|
|
|
|
$schema{ $class_key }= $classes{$class_key};
|
141
|
|
|
|
|
|
|
}
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
0
|
|
|
|
my $isa = $cfg->{bases} || $reflex->{isa};
|
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
$schema{$class}->{bases} = $isa if $isa;
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
}
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return [ %schema ];
|
156
|
|
|
|
|
|
|
}
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1;
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__
|