line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CogBase::Factory; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
4
|
use CogBase::Base -base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
field 'connection'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new_node { |
9
|
2
|
|
|
2
|
0
|
23
|
my ($self, $type) = @_; |
10
|
2
|
50
|
|
|
|
15
|
die "'$type' is invalid type" |
11
|
|
|
|
|
|
|
unless $type =~ /^ |
12
|
|
|
|
|
|
|
( |
13
|
|
|
|
|
|
|
Schema |
14
|
|
|
|
|
|
|
| |
15
|
|
|
|
|
|
|
[[:lower:]] |
16
|
|
|
|
|
|
|
[_[:word:]]+ |
17
|
|
|
|
|
|
|
) |
18
|
|
|
|
|
|
|
$/xo; |
19
|
2
|
|
|
|
|
8
|
$self->require_node_class($type); |
20
|
1
|
|
|
|
|
5
|
my $class = "CogBase::$type"; |
21
|
1
|
|
|
|
|
6
|
return $class->New(Type => $type); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub require_node_class { |
25
|
2
|
|
|
2
|
0
|
6
|
my ($self, $type) = @_; |
26
|
2
|
|
|
|
|
6
|
my $class = "CogBase::$type"; |
27
|
2
|
50
|
|
|
|
20
|
return if $class->can('New'); |
28
|
2
|
|
|
|
|
125
|
eval "require $class"; |
29
|
2
|
100
|
|
|
|
51
|
return if $class->can('New'); |
30
|
1
|
|
|
|
|
7
|
$self->generate_class($type); |
31
|
0
|
0
|
|
|
|
0
|
return if $class->can('New'); |
32
|
0
|
|
|
|
|
0
|
die "Can't create node of unknown type '$type'"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub generate_class { |
36
|
1
|
|
|
1
|
0
|
1193
|
require YAML::Syck; |
37
|
1
|
|
|
|
|
2779
|
my ($self, $type) = @_; |
38
|
1
|
|
|
|
|
47
|
my $schema_node = $self->connection->fetchSchemaNode($type); |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
26
|
my $hash = eval { YAML::Syck::Load($schema_node->value) }; |
|
1
|
|
|
|
|
21
|
|
41
|
1
|
50
|
|
|
|
14
|
die "Schema has invalid YAML: $@" if $@; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
eval <<"..."; |
44
|
0
|
|
|
|
|
|
# $schema_node->{Id} |
45
|
|
|
|
|
|
|
package CogBase::$hash->{'+'}; |
46
|
|
|
|
|
|
|
use strict; |
47
|
|
|
|
|
|
|
use CogBase::$hash->{'<'} -base; |
48
|
|
|
|
|
|
|
${ \ $self->format_fields($hash) } |
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
... |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub format_fields { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $hash) = @_; |
55
|
0
|
|
|
|
|
|
my $output = ''; |
56
|
0
|
|
|
|
|
|
for my $field (keys %$hash) { |
57
|
0
|
0
|
|
|
|
|
next unless $field =~ /^\w/; |
58
|
0
|
|
|
|
|
|
$output .= "field '$field';\n"; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
return $output; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |