CogBase/Factory.pm

filter: Statementstmt 73.6% 28 / 38 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 4 totaltotal 63.9% 39 / 61 CC 8 SCAR 15.5
CC
8
Cov
66%
format_fields
12.0
require_node_class
4.7
generate_class
2.1
CRAP 4.7
↑ Summary CogBase/Connection.pm »
1 package CogBase::Factory;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use CogBase::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 field 'connection';
7  
8 2 ▶sub new_node {
Subroutine new_node: called CC=2 SCAR=7.0
Pod undocumented
9 2 my ($self, $type) = @_;
10 2 ▶ die "'$type' is invalid type"
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^ ( Schema | [[:lower:]] [_[:word:]]+ ) $/ox 0 2 2
11 unless $type =~ /^
12 (
13 Schema
14 |
15 [[:lower:]]
16 [_[:word:]]+
17 )
18 $/xo;
19 2 $self->require_node_class($type);
20 1 my $class = "CogBase::$type";
21 1 return $class->New(Type => $type);
22 }
23  
24 2 ▶sub require_node_class {
Subroutine require_node_class: called CC=4 SCAR=15.5
Pod undocumented
25 2 my ($self, $type) = @_;
26 2 my $class = "CogBase::$type";
27 2 ▶ return if $class->can('New');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("New") 0 2 2
28 2 eval "require $class";
29 2 ▶ return if $class->can('New');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("New") 1 1 2
30 1 $self->generate_class($type);
31 0 ▶ return if $class->can('New');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("New") 0 0 0
32 0 die "Can't create node of unknown type '$type'";
33 }
34  
35 1 ▶sub generate_class {
Subroutine generate_class: called CC=2 SCAR=7.5
Pod undocumented
36 1 require YAML::Syck;
37 1 my ($self, $type) = @_;
38 1 my $schema_node = $self->connection->fetchSchemaNode($type);
39  
40 1 my $hash = eval { YAML::Syck::Load($schema_node->value) };
41 1 ▶ die "Schema has invalid YAML: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
42  
43 0 eval <<"...";
44 # $schema_node->{Id}
45 package CogBase::$hash->{'+'};
46 use strict;
47 use CogBase::$hash->{'<'} -base;
48 0 ${ \ $self->format_fields($hash) }
49 1;
50 ...
51 }
52  
53 0 ▶sub format_fields {
Subroutine format_fields: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my ($self, $hash) = @_;
55 0 my $output = '';
56 0 for my $field (keys %$hash) {
57 0 ▶ next unless $field =~ /^\w/;
Branch: 1 branch
BranchTrueFalseTotal
unless $field =~ /^\w/ 0 0 0
58 0 $output .= "field '$field';\n";
59 }
60 0 return $output;
61 }
62  
63 1 1;
↑ Summary CogBase/Connection.pm »