| 1 | 10 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | #======================================================= | ||||||||||||||||||||||||||||
| 7 | package XML::Pastor::Generator; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use File::Path; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use Class::Accessor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use XML::Pastor::Util qw(mergeHash module_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 10 | our @ISA = qw(Class::Accessor); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 9 | my $proto = shift; | |||||||||||||||||||||||||||
| 21 | 9 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 22 | 9 | my $self = {@_}; | |||||||||||||||||||||||||||
| 23 | 9 | return bless $self, $class; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 27 | # Generate Perl code from a given schema model (produced by the Parser) by the | ||||||||||||||||||||||||||||
| 28 | # argument 'model'. | ||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||
| 30 | # Understands several modes of functioning => generate, eval, return | ||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||
| 32 | # mode = 'offline' : Generate perl code and write it to one or more module files. | ||||||||||||||||||||||||||||
| 33 | # mode = 'eval' : Generate perl code and 'evaluate' it in situ without writing out to any file. | ||||||||||||||||||||||||||||
| 34 | # mode = 'return' : Generate perl code and return the resulting string to the caller. | ||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||
| 36 | # Understands also two styles: | ||||||||||||||||||||||||||||
| 37 | # style = 'single' : Generate one big chunk of code with all the packages in it. | ||||||||||||||||||||||||||||
| 38 | # Note that this is the forced case when mode is 'eval' or 'return' | ||||||||||||||||||||||||||||
| 39 | # style = 'multiple': Generate one chunk of code for each class and write it out to multiple | ||||||||||||||||||||||||||||
| 40 | # module files within the 'destination' directory. | ||||||||||||||||||||||||||||
| 41 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 42 | 9 | ▶ | sub generate { | ||||||||||||||||||||||||||
|
Subroutine
generate: called CC=13 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 9 | my $args = {@_}; | |||||||||||||||||||||||||||
| 45 | 9 | ▶ | my $model = $args->{model} or die "Pastor: Code generation requires a 'model'!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 9 | my $mode = $args->{mode}; | |||||||||||||||||||||||||||
| 47 | 9 | ▶ | if ( ($mode =~ /eval/) || ($mode =~ /return/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mode =~ /eval/ or $mode =~ /return/
MC/DC50%1/2
$mode =~ /eval/ or $mode =~ /return/
$mode =~ /eval/
$mode =~ /return/
Truth table66%2/3
A or B
A= $mode =~ /eval/B= $mode =~ /return/
| |||||||||||||||||||||||||||||
| 48 | 8 | $args->{style} = "single"; # force single module generation | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 9 | my $style = $args->{style}; | |||||||||||||||||||||||||||
| 51 | 9 | ▶ | my $destination = $args->{destination} || '/tmp/lib/perl/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'destination'} || '/tmp/lib/perl/'
MC/DC0%0/1
$args->{'destination'} || '/tmp/lib/perl/'
$args->{'destination'}
Truth table50%1/2
A
A= $args->{'destination'}
| |||||||||||||||||||||||||||||
| 52 | 9 | ▶ | my $verbose = $self->{verbose} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'verbose'} || 0
MC/DC0%0/1
$self->{'verbose'} || 0
$self->{'verbose'}
Truth table50%1/2
A
A= $self->{'verbose'}
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # If 'destination' doesn't end with a trailing slash, add one. | ||||||||||||||||||||||||||||
| 55 | 9 | ▶ | if ($destination && ($destination !~ /\/$/) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$destination and not $destination =~ m[/$]
MC/DC0%0/2
$destination and not $destination =~ m[/$]
$destination
not $destination =~ m[/$]
Truth table33%1/3
A and not(B)
A= $destinationB= not $destination =~ m[/$]
| |||||||||||||||||||||||||||||
| 56 | 0 | $destination .= '/'; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 9 | $args->{destination}= $destination; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 9 | ▶ | my $class_prefix = $args->{class_prefix} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'class_prefix'} || ''
MC/DC0%0/1
$args->{'class_prefix'} || ''
$args->{'class_prefix'}
Truth table50%1/2
A
A= $args->{'class_prefix'}
| |||||||||||||||||||||||||||||
| 61 | 9 | ▶ | while (($class_prefix) && ($class_prefix !~ /::$/)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class_prefix and not $class_prefix =~ /::$/
MC/DC50%1/2
$class_prefix and not $class_prefix =~ /::$/
$class_prefix
not $class_prefix =~ /::$/
Truth table66%2/3
A and not(B)
A= $class_prefixB= not $class_prefix =~ /::$/
| |||||||||||||||||||||||||||||
| 62 | 14 | $class_prefix .= ':'; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 9 | $args->{metaModule} = $class_prefix . "Pastor::Meta"; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 9 | ▶ | print STDERR "\nGenerating code...\n" if ($verbose >=2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 9 | ▶ | if ($style =~ /single/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 8 | $self->_generateSingle(%$args); | |||||||||||||||||||||||||||
| 70 | }else { | ||||||||||||||||||||||||||||
| 71 | 1 | $self->_generateMultiple(%$args); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 76 | # Generate a single chunk of code, putting all the classes (packages) into that | ||||||||||||||||||||||||||||
| 77 | # chunk. Then write to a module file if requested | ||||||||||||||||||||||||||||
| 78 | # or otherwise evaluate it or just return it (depending on the 'mode') | ||||||||||||||||||||||||||||
| 79 | 8 | ▶ | sub _generateSingle { | ||||||||||||||||||||||||||
|
Subroutine
_generateSingle: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||
| 80 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 8 | my $args = {@_}; | |||||||||||||||||||||||||||
| 82 | 8 | my $model = $args->{model}; | |||||||||||||||||||||||||||
| 83 | 8 | my $mode = $args->{mode}; | |||||||||||||||||||||||||||
| 84 | 8 | my $class_prefix = $args->{class_prefix}; | |||||||||||||||||||||||||||
| 85 | 8 | ▶ | my $module = $args->{module} || $class_prefix; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'module'} || $class_prefix
MC/DC0%0/2
$args->{'module'} || $class_prefix
$args->{'module'}
$class_prefix
Truth table33%1/3
A || B
A= $args->{'module'}B= $class_prefix
| |||||||||||||||||||||||||||||
| 86 | 8 | my $code = $self->_fabricatePrelude(@_); | |||||||||||||||||||||||||||
| 87 | 8 | ▶ | my $destination = $args->{destination} || '/tmp/lib/perl/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'destination'} || '/tmp/lib/perl/'
MC/DC0%0/1
$args->{'destination'} || '/tmp/lib/perl/'
$args->{'destination'}
Truth table50%1/2
A
A= $args->{'destination'}
| |||||||||||||||||||||||||||||
| 88 | 8 | ▶ | my $verbose = $self->{verbose} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'verbose'} || 0
MC/DC0%0/1
$self->{'verbose'} || 0
$self->{'verbose'}
Truth table50%1/2
A
A= $self->{'verbose'}
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 8 | foreach my $items ($model->type(), $model->element()) { | |||||||||||||||||||||||||||
| 91 | 16 | foreach my $key (sort keys %$items) { | |||||||||||||||||||||||||||
| 92 | 134 | $code .= $self->_fabricateCode(@_, object=>$items->{$key}); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 8 | $code .= $self->_fabricateHeaderModuleCode(@_); | |||||||||||||||||||||||||||
| 97 | 8 | $code .= $self->_fabricateMetaModuleCode(@_); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Perl modules must return TRUE | ||||||||||||||||||||||||||||
| 100 | 8 | $code .= "\n\n1;\n"; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 8 | ▶ | print STDERR "\n****** CODE STARTS *******" . $code . "\n***** CODE ENDS *****\n" if ($verbose >=9); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 8 | ▶ | if ($mode =~ /eval/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 105 | # evaluate the code | ||||||||||||||||||||||||||||
| 106 | 8 | ▶ | eval $code; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
code: not called CC=1 SCAR=0.0
Subroutine
code: not called CC=1 SCAR=0.0
Subroutine
code: not called CC=1 SCAR=0.0
Subroutine
date: not called CC=1 SCAR=0.0
Subroutine
figure: not called CC=1 SCAR=0.0
Subroutine
lang: not called CC=1 SCAR=0.0
Subroutine
name: not called CC=1 SCAR=0.0
Subroutine
airport: not called CC=1 SCAR=0.0
Subroutine
borderCrossing: not called CC=1 SCAR=0.0
Subroutine
code: not called CC=1 SCAR=0.0
Subroutine
code2: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 107 | 8 | ▶ | $@ and die "$@\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | }elsif ($mode =~ /return/) { | ||||||||||||||||||||||||||||
| 109 | # just return the code | ||||||||||||||||||||||||||||
| 110 | 0 | return $code; | |||||||||||||||||||||||||||
| 111 | }else { | ||||||||||||||||||||||||||||
| 112 | # generate module | ||||||||||||||||||||||||||||
| 113 | 0 | my $file = module_path(module => $module, destination => $destination); | |||||||||||||||||||||||||||
| 114 | 0 | $self->_writeCode(@_, file=>$file, code=>$code); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 8 | return $self; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 120 | # Generate a multiple 'modules' of code, one for each class. | ||||||||||||||||||||||||||||
| 121 | # Then write the code to module files within the 'destination' directory | ||||||||||||||||||||||||||||
| 122 | 31 | ▶ | sub _generateMultiple { | ||||||||||||||||||||||||||
|
Subroutine
_generateMultiple: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 123 | 31 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 1 | my $args = {@_}; | |||||||||||||||||||||||||||
| 125 | 13 | my $model = $args->{model}; | |||||||||||||||||||||||||||
| 126 | 1 | my $class_prefix = $args->{class_prefix}; | |||||||||||||||||||||||||||
| 127 | 4 | ▶ | my $module = $args->{module} || $class_prefix; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'module'} || $class_prefix
MC/DC0%0/2
$args->{'module'} || $class_prefix
$args->{'module'}
$class_prefix
Truth table33%1/3
A || B
A= $args->{'module'}B= $class_prefix
| |||||||||||||||||||||||||||||
| 128 | 1 | my $metaModule = $args->{metaModule}; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 4 | my $types = $model->type(); | |||||||||||||||||||||||||||
| 131 | 5 | ▶ | my $destination = $args->{destination} || '/tmp/lib/perl/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'destination'} || '/tmp/lib/perl/'
MC/DC0%0/1
$args->{'destination'} || '/tmp/lib/perl/'
$args->{'destination'}
Truth table50%1/2
A
A= $args->{'destination'}
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 3 | foreach my $items ($model->type(), $model->element()) { | |||||||||||||||||||||||||||
| 134 | 2 | foreach my $key (sort keys %$items) { | |||||||||||||||||||||||||||
| 135 | 15 | my $object = $items->{$key}; | |||||||||||||||||||||||||||
| 136 | 15 | my $code = $self->_fabricateCode(@_, object=>$object); | |||||||||||||||||||||||||||
| 137 | 15 | $code .= "\n\n__END__\n\n"; | |||||||||||||||||||||||||||
| 138 | 15 | $code .=$self->_fabricatePod(@_, object=>$object); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 15 | my $file = module_path(module => $object->class(), destination => $destination); | |||||||||||||||||||||||||||
| 141 | 15 | $self->_writeCode(@_, file=>$file, code=>$code); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # META mdoule | ||||||||||||||||||||||||||||
| 146 | 1 | my $code = $self->_fabricateMetaModuleCode(@_); | |||||||||||||||||||||||||||
| 147 | 1 | my $file = module_path(module => $metaModule, destination => $destination); | |||||||||||||||||||||||||||
| 148 | 1 | $self->_writeCode(@_, file=>$file, code=>$code); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # HEADER module | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if ($module) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | # Generate the module with all the 'use' statements for different modules. | ||||||||||||||||||||||||||||
| 154 | 1 | my $code = $self->_fabricateHeaderModuleCode(@_); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | my $file = module_path(module => $module, destination => $destination); | |||||||||||||||||||||||||||
| 157 | 1 | $self->_writeCode(@_, file=>$file, code=>$code); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | return $self; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 165 | # Fabricate the code for the module that will 'use' all the generated classes. | ||||||||||||||||||||||||||||
| 166 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 167 | 9 | ▶ | sub _fabricateHeaderModuleCode { | ||||||||||||||||||||||||||
|
Subroutine
_fabricateHeaderModuleCode: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 168 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 169 | 9 | my $args = {@_}; | |||||||||||||||||||||||||||
| 170 | 9 | my $model = $args->{model}; | |||||||||||||||||||||||||||
| 171 | 9 | my $style = $args->{style}; | |||||||||||||||||||||||||||
| 172 | 9 | my $class_prefix = $args->{class_prefix}; | |||||||||||||||||||||||||||
| 173 | 9 | ▶ | my $module = $args->{module} || $class_prefix; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'module'} || $class_prefix
MC/DC0%0/2
$args->{'module'} || $class_prefix
$args->{'module'}
$class_prefix
Truth table33%1/3
A || B
A= $args->{'module'}B= $class_prefix
| |||||||||||||||||||||||||||||
| 174 | 9 | my $metaModule = $args->{metaModule}; | |||||||||||||||||||||||||||
| 175 | 9 | my $code; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # get ride of any trailing columns. | ||||||||||||||||||||||||||||
| 178 | 9 | ▶ | while ($module =~ /:$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 4 | $module =~ s/:$//; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 9 | ▶ | $code = _fabricatePrelude(@_) unless ($style =~ /single/i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 9 | $code .= "\n\npackage $module;\n"; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # USE | ||||||||||||||||||||||||||||
| 185 | 9 | ▶ | unless ($style =~ /single/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 1 | foreach my $items ($model->type(), $model->element()) { | |||||||||||||||||||||||||||
| 187 | 2 | foreach my $name (sort keys %$items) { | |||||||||||||||||||||||||||
| 188 | 15 | my $object = $items->{$name}; | |||||||||||||||||||||||||||
| 189 | 15 | my $class = $object->class(); | |||||||||||||||||||||||||||
| 190 | 15 | $code .= "\nuse $class;" | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | ▶ | $code .= "\n\nuse $metaModule;" if ($metaModule); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # EPILOGUE | ||||||||||||||||||||||||||||
| 198 | 9 | ▶ | unless ($style =~ /single/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | # Perl modules must return TRUE | ||||||||||||||||||||||||||||
| 200 | 1 | $code .= "\n\n1;\n"; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 9 | return $code; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 208 | # Fabricate the first prelude stub of code for each module. | ||||||||||||||||||||||||||||
| 209 | # Needed only in the begining of each physical module file. | ||||||||||||||||||||||||||||
| 210 | 37 | ▶ | sub _fabricatePrelude { | ||||||||||||||||||||||||||
|
Subroutine
_fabricatePrelude: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 211 | 25 | my $self = shift; | |||||||||||||||||||||||||||
| 212 | 25 | my $code = ""; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 25 | $code .= "\n#PASTOR: Code generated by XML::Pastor/" . XML::Pastor->version() . " at '" . localtime() . "'\n"; | |||||||||||||||||||||||||||
| 215 | 25 | $code .= "\nuse utf8;"; | |||||||||||||||||||||||||||
| 216 | 25 | $code .= "\nuse strict;"; | |||||||||||||||||||||||||||
| 217 | 25 | $code .= "\nuse warnings;"; | |||||||||||||||||||||||||||
| 218 | 25 | $code .= "\nno warnings qw(uninitialized);"; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 25 | $code .= "\n\nuse XML::Pastor;\n\n"; | |||||||||||||||||||||||||||
| 221 | 25 | return $code; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 225 | # Fabricate the code for the META module. | ||||||||||||||||||||||||||||
| 226 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 227 | 9 | ▶ | sub _fabricateMetaModuleCode { | ||||||||||||||||||||||||||
|
Subroutine
_fabricateMetaModuleCode: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 228 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 229 | 9 | my $args = {@_}; | |||||||||||||||||||||||||||
| 230 | 9 | my $model = $args->{model}; | |||||||||||||||||||||||||||
| 231 | 9 | my $style = $args->{style}; | |||||||||||||||||||||||||||
| 232 | 9 | my $module = $args->{metaModule}; | |||||||||||||||||||||||||||
| 233 | 9 | my $isa = [qw(XML::Pastor::Meta)]; | |||||||||||||||||||||||||||
| 234 | 9 | my $code = ""; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 9 | ▶ | $code = _fabricatePrelude(@_) unless ($style =~ /single/i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 9 | $code .= "\n\npackage $module;\n"; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # ISA | ||||||||||||||||||||||||||||
| 242 | 9 | $code .= "\n\nour " . '@ISA=qw(' . join (' ', @$isa) . ");"; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # Model | ||||||||||||||||||||||||||||
| 245 | 9 | $code .= "\n\n$module->Model( " ; | |||||||||||||||||||||||||||
| 246 | 9 | $code .= _dumpObject($model); | |||||||||||||||||||||||||||
| 247 | 9 | $code =~ s/\n$//; | |||||||||||||||||||||||||||
| 248 | 9 | $code .=" );"; | |||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # EPILOGUE | ||||||||||||||||||||||||||||
| 251 | 9 | ▶ | unless ($style =~ /single/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | # Perl modules must return TRUE | ||||||||||||||||||||||||||||
| 253 | 1 | $code .= "\n\n1;\n"; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 9 | return $code; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 263 | # Fabricate the code for one given class (type). | ||||||||||||||||||||||||||||
| 264 | # Can work in 'single' or 'multiple' style (knows to distinguish them). | ||||||||||||||||||||||||||||
| 265 | # Will create code in a separate 'package' section for the class. | ||||||||||||||||||||||||||||
| 266 | 152 | ▶ | sub _fabricateCode { | ||||||||||||||||||||||||||
|
Subroutine
_fabricateCode: called CC=23 SCAR=31.6
| |||||||||||||||||||||||||||||
| 267 | 149 | my $self = shift; | |||||||||||||||||||||||||||
| 268 | 149 | my $args = {@_}; | |||||||||||||||||||||||||||
| 269 | 149 | ▶ | my $object = $args->{object} or die "Pastor: _fabricateCode: Need a type!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 149 | my $style = $args->{style}; | |||||||||||||||||||||||||||
| 271 | 149 | my $class = $object->class(); | |||||||||||||||||||||||||||
| 272 | 149 | ▶ | my $isa = $object->baseClasses() || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$object->baseClasses || []
MC/DC0%0/1
$object->baseClasses || []
$object->baseClasses
Truth table50%1/2
A
A= $object->baseClasses
| |||||||||||||||||||||||||||||
| 273 | 149 | ▶ | my $verbose = $self->{verbose} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'verbose'} || 0
MC/DC0%0/1
$self->{'verbose'} || 0
$self->{'verbose'}
Truth table50%1/2
A
A= $self->{'verbose'}
| |||||||||||||||||||||||||||||
| 274 | 149 | my $code = ""; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 149 | ▶ | print STDERR "\nFabricating code for class '$class' ..." if ($verbose >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # PRELUDE | ||||||||||||||||||||||||||||
| 279 | 149 | ▶ | $code .= $self->_fabricatePrelude(@_) unless ($style =~ /single/i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # package | ||||||||||||||||||||||||||||
| 282 | 149 | $code .= "\n\n#================================================================"; | |||||||||||||||||||||||||||
| 283 | 149 | $code .= "\n\npackage $class;\n"; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | # use | ||||||||||||||||||||||||||||
| 286 | # in "single" style, we won't need the use clauses because all packages will be in one module. | ||||||||||||||||||||||||||||
| 287 | 149 | ▶ | unless ($style =~ /single/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 15 | my $uses = $self->_calculateUses($object, {@_}); | |||||||||||||||||||||||||||
| 289 | 15 | foreach my $use (sort keys %$uses) { | |||||||||||||||||||||||||||
| 290 | 33 | ▶ | next if $use eq $class; # We won't be using ourselves! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 18 | $code .= "\nuse $use;"; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # ISA | ||||||||||||||||||||||||||||
| 296 | 149 | $code .= "\n\nour " . '@ISA=qw(' . join (' ', @$isa) . ");"; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | # mk_accessors | ||||||||||||||||||||||||||||
| 299 | 149 | my $accessors = []; | |||||||||||||||||||||||||||
| 300 | 149 | ▶ | if (UNIVERSAL::can($object, "attributes")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 58 | my $attribPfx = ""; | |||||||||||||||||||||||||||
| 302 | 58 | ▶ | $attribPfx = $object->attributePrefix() if (UNIVERSAL::can($object, "attributePrefix")); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | 58 | my $fields = [map {$attribPfx . $_} @{$object->attributes()}]; | |||||||||||||||||||||||||||
| 304 | 58 | push @$accessors, @$fields; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | 149 | ▶ | if (UNIVERSAL::can($object, "elements")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 58 | push @$accessors, @{$object->elements()}; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | 149 | ▶ | if ( scalar(@$accessors) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 58 | $code .= "\n\n$class". '->mk_accessors( qw(' . join (' ', @$accessors) . "));"; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | # Attribute accessor aliases | ||||||||||||||||||||||||||||
| 315 | 149 | ▶ | if (UNIVERSAL::can($object, "attributes")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 58 | my $attributes = $object->attributes(); | |||||||||||||||||||||||||||
| 317 | 58 | ▶ | my $attribPfx = (UNIVERSAL::can($object, "attributePrefix")) ? $object->attributePrefix() : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 58 | ▶ | if (scalar(@$attributes) && $attribPfx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @$attributes and $attribPfx
MC/DC50%1/2
scalar @$attributes and $attribPfx
scalar @$attributes
$attribPfx
Truth table66%2/3
A and B
A= scalar @$attributesB= $attribPfx
| |||||||||||||||||||||||||||||
| 320 | 48 | $code .= "\n\n# Attribute accessor aliases\n"; | |||||||||||||||||||||||||||
| 321 | 48 | ▶ | my $elementInfo = (UNIVERSAL::can($object, "effectiveElementInfo")) ? $object->effectiveElementInfo() : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 48 | foreach my $attribute (@$attributes) { | |||||||||||||||||||||||||||
| 323 | 90 | ▶ | next if defined($elementInfo->{$attribute}); # Attribute/Element name conflict. No alias possible | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 90 | my $field = $attribPfx . $attribute; | |||||||||||||||||||||||||||
| 325 | 90 | ▶ | next if ($field eq $attribute); # No attribute prefix. No need for an alias. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 90 | $code .= "\nsub $attribute { &" . $field . '; }'; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # XmlSchemaInfo | ||||||||||||||||||||||||||||
| 335 | 149 | ▶ | if (UNIVERSAL::isa($object, "XML::Pastor::Schema::Element")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 41 | $code .= "\n\n$class->XmlSchemaElement( " ; | |||||||||||||||||||||||||||
| 337 | }else { | ||||||||||||||||||||||||||||
| 338 | 108 | $code .= "\n\n$class->XmlSchemaType( " ; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | 149 | $code .= _dumpObject($object); | |||||||||||||||||||||||||||
| 341 | 149 | $code =~ s/\n$//; | |||||||||||||||||||||||||||
| 342 | 149 | $code .=" );"; | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | # EPILOGUE | ||||||||||||||||||||||||||||
| 346 | 149 | ▶ | unless ($style =~ /single/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | # Perl modules must return TRUE | ||||||||||||||||||||||||||||
| 348 | 15 | $code .= "\n\n1;\n"; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 149 | return $code; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 355 | # Figure out the classes that need to be 'used' by a given class. | ||||||||||||||||||||||||||||
| 356 | # This is needed to create the 'use' stubs in code generation. | ||||||||||||||||||||||||||||
| 357 | 31 | ▶ | sub _calculateUses { | ||||||||||||||||||||||||||
|
Subroutine
_calculateUses: called CC=25 SCAR=32.9
| |||||||||||||||||||||||||||||
| 358 | 31 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 31 | my $object = shift; | |||||||||||||||||||||||||||
| 360 | 31 | my $opts = shift; | |||||||||||||||||||||||||||
| 361 | 31 | my $result = {}; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 31 | ▶ | if (UNIVERSAL::can($object, "class") && $object->class()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
UNIVERSAL::can($object, "class") and $object->class
MC/DC0%0/2
UNIVERSAL::can($object, "class") and $object->class
UNIVERSAL::can($object, "class")
$object->class
Truth table33%1/3
A and B
A= UNIVERSAL::can($object, "class")B= $object->class
| |||||||||||||||||||||||||||||
| 364 | 31 | my $class = $object->class(); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | # Consider the class as 'used' unless it starts with XML::Pastor which is handled differently | ||||||||||||||||||||||||||||
| 367 | # But XML::Pastor::Test::* are used for testing purposes. | ||||||||||||||||||||||||||||
| 368 | SWITCH: { | ||||||||||||||||||||||||||||
| 369 | 31 | (($class =~ /^XML::Pastor::/) && | |||||||||||||||||||||||||||
| 370 | 31 | ▶ | ($class !~ /^XML::Pastor::Test/)) and do {last SWITCH;}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
MC/DC50%1/2
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
$class =~ /^XML::Pastor::/
not $class =~ /^XML::Pastor::Test/
Truth table66%2/3
A and not(B)
A= $class =~ /^XML::Pastor::/B= not $class =~ /^XML::Pastor::Test/
| |||||||||||||||||||||||||||||
| 371 | 24 | OTHERWISE: { $result->{$class}=1; last SWITCH;} | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 31 | ▶ | if (UNIVERSAL::can($object, "itemClass") && $object->itemClass()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
UNIVERSAL::can($object, "itemClass") and $object->itemClass
MC/DC100%2/2
UNIVERSAL::can($object, "itemClass") and $object->itemClass
UNIVERSAL::can($object, "itemClass")
$object->itemClass
Truth table100%3/3
A and B
A= UNIVERSAL::can($object, "itemClass")B= $object->itemClass
| |||||||||||||||||||||||||||||
| 377 | 1 | my $class = $object->itemClass(); | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | # Consider the class as 'used' unless it starts with XML::Pastor which is handled differently | ||||||||||||||||||||||||||||
| 380 | # But XML::Pastor::Test::* are used for testing purposes. | ||||||||||||||||||||||||||||
| 381 | SWITCH: { | ||||||||||||||||||||||||||||
| 382 | 1 | (($class =~ /^XML::Pastor::/) && | |||||||||||||||||||||||||||
| 383 | 0 | ▶ | ($class !~ /^XML::Pastor::Test/)) and do {last SWITCH;}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
MC/DC0%0/2
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
$class =~ /^XML::Pastor::/
not $class =~ /^XML::Pastor::Test/
Truth table33%1/3
A and not(B)
A= $class =~ /^XML::Pastor::/B= not $class =~ /^XML::Pastor::Test/
| |||||||||||||||||||||||||||||
| 384 | 1 | OTHERWISE: { $result->{$class}=1; last SWITCH;} | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 31 | ▶ | if (UNIVERSAL::can($object, "baseClasses") && $object->baseClasses()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
UNIVERSAL::can($object, "baseClasses") and $object->baseClasses
MC/DC100%2/2
UNIVERSAL::can($object, "baseClasses") and $object->baseClasses
UNIVERSAL::can($object, "baseClasses")
$object->baseClasses
Truth table100%3/3
A and B
A= UNIVERSAL::can($object, "baseClasses")B= $object->baseClasses
| |||||||||||||||||||||||||||||
| 391 | 18 | my $isa = $object->baseClasses(); | |||||||||||||||||||||||||||
| 392 | 18 | foreach my $class (@$isa) { | |||||||||||||||||||||||||||
| 393 | # Consider the class as 'used' unless it starts with XML::Pastor which is handled differently | ||||||||||||||||||||||||||||
| 394 | # But XML::Pastor::Test::* are used for testing purposes. | ||||||||||||||||||||||||||||
| 395 | SWITCH: { | ||||||||||||||||||||||||||||
| 396 | 24 | (($class =~ /^XML::Pastor::/) && | |||||||||||||||||||||||||||
| 397 | 24 | ▶ | ($class !~ /^XML::Pastor::Test/)) and do {last SWITCH;}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
MC/DC50%1/2
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
$class =~ /^XML::Pastor::/
not $class =~ /^XML::Pastor::Test/
Truth table66%2/3
A and not(B)
A= $class =~ /^XML::Pastor::/B= not $class =~ /^XML::Pastor::Test/
| |||||||||||||||||||||||||||||
| 398 | 6 | OTHERWISE: { $result->{$class}=1; last SWITCH;} | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 31 | ▶ | if (UNIVERSAL::can($object, "memberClasses") && $object->memberClasses()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
UNIVERSAL::can($object, "memberClasses") and $object->memberClasses
MC/DC100%2/2
UNIVERSAL::can($object, "memberClasses") and $object->memberClasses
UNIVERSAL::can($object, "memberClasses")
$object->memberClasses
Truth table100%3/3
A and B
A= UNIVERSAL::can($object, "memberClasses")B= $object->memberClasses
| |||||||||||||||||||||||||||||
| 404 | 2 | my $mbcs = $object->memberClasses(); | |||||||||||||||||||||||||||
| 405 | 2 | foreach my $class (@$mbcs) { | |||||||||||||||||||||||||||
| 406 | # Consider the class as 'used' unless it starts with XML::Pastor which is handled differently | ||||||||||||||||||||||||||||
| 407 | # But XML::Pastor::Test::* are used for testing purposes. | ||||||||||||||||||||||||||||
| 408 | SWITCH: { | ||||||||||||||||||||||||||||
| 409 | 5 | (($class =~ /^XML::Pastor::/) && | |||||||||||||||||||||||||||
| 410 | 0 | ▶ | ($class !~ /^XML::Pastor::Test/)) and do {last SWITCH;}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
MC/DC0%0/2
$class =~ /^XML::Pastor::/ and not $class =~ /^XML::Pastor::Test/
$class =~ /^XML::Pastor::/
not $class =~ /^XML::Pastor::Test/
Truth table33%1/3
A and not(B)
A= $class =~ /^XML::Pastor::/B= not $class =~ /^XML::Pastor::Test/
| |||||||||||||||||||||||||||||
| 411 | 5 | OTHERWISE: { $result->{$class}=1; last SWITCH;} | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 31 | ▶ | if (UNIVERSAL::can($object, "definition") && $object->definition()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
UNIVERSAL::can($object, "definition") and $object->definition
MC/DC50%1/2
UNIVERSAL::can($object, "definition") and $object->definition
UNIVERSAL::can($object, "definition")
$object->definition
Truth table66%2/3
A and B
A= UNIVERSAL::can($object, "definition")B= $object->definition
| |||||||||||||||||||||||||||||
| 419 | 3 | mergeHash($result, $self->_calculateUses($object->definition(), $opts)); | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 31 | ▶ | if (UNIVERSAL::can($object, "attributeInfo")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 5 | foreach my $attrib (values %{$object->attributeInfo()} ){ | |||||||||||||||||||||||||||
| 424 | 7 | mergeHash($result, $self->_calculateUses($attrib, $opts)); | |||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 31 | ▶ | if (UNIVERSAL::can($object, "elementInfo")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 5 | foreach my $elem (values %{$object->elementInfo()} ){ | |||||||||||||||||||||||||||
| 430 | 6 | mergeHash($result, $self->_calculateUses($elem, $opts)); | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 31 | return $result; | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 438 | # Fabricate the POD for one given class (type). | ||||||||||||||||||||||||||||
| 439 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 440 | 18 | ▶ | sub _fabricatePod { | ||||||||||||||||||||||||||
|
Subroutine
_fabricatePod: called CC=20 SCAR=30.3
| |||||||||||||||||||||||||||||
| 441 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 442 | 15 | my $args = {@_}; | |||||||||||||||||||||||||||
| 443 | 15 | ▶ | my $object = $args->{object} or die "Pastor: _fabricatePod: Need a type!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | 15 | my $style = $args->{style}; | |||||||||||||||||||||||||||
| 445 | 15 | my $class = $object->class(); | |||||||||||||||||||||||||||
| 446 | 15 | ▶ | my $isa = $object->baseClasses() || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$object->baseClasses || []
MC/DC0%0/1
$object->baseClasses || []
$object->baseClasses
Truth table50%1/2
A
A= $object->baseClasses
| |||||||||||||||||||||||||||||
| 447 | 15 | ▶ | my $verbose = $self->{verbose} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'verbose'} || 0
MC/DC0%0/1
$self->{'verbose'} || 0
$self->{'verbose'}
Truth table50%1/2
A
A= $self->{'verbose'}
| |||||||||||||||||||||||||||||
| 448 | 15 | my $pod = ""; | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 15 | ▶ | print STDERR "\nFabricating POD for class '$class' ..." if ($verbose >= 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | # NAME | ||||||||||||||||||||||||||||
| 453 | 15 | $pod .= "\n\n=head1 NAME\n\nB<$class> - A class generated by L<XML::Pastor> . \n"; | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 456 | 15 | ▶ | if (defined $object->documentation) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | 1 | $pod .= "\n\n=head1 DESCRIPTION\n"; | |||||||||||||||||||||||||||
| 458 | 1 | foreach my $doc (@{$object->documentation}) { | |||||||||||||||||||||||||||
| 459 | 1 | my $text = $doc->text; | |||||||||||||||||||||||||||
| 460 | 1 | $text =~ s/^\s+//; # chop leading space. | |||||||||||||||||||||||||||
| 461 | 1 | $pod .= "\n" . $text . "\n"; | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | # ISA | ||||||||||||||||||||||||||||
| 467 | 15 | $pod .= "\n\n=head1 ISA\n\nThis class descends from " . join(', ', map {"L<$_>"} @$isa) . ".\n"; | |||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | # CODE GENERATION | ||||||||||||||||||||||||||||
| 470 | 15 | $pod .= "\n\n=head1 CODE GENERATION\n\nThis module was automatically generated by L<XML::Pastor> version " . $XML::Pastor::VERSION . " at '" . localtime() . "'\n"; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | # ATTRIBUTE Accessors | ||||||||||||||||||||||||||||
| 473 | 15 | ▶ | if (UNIVERSAL::can($object, "attributes") && scalar(@{$object->attributes})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
UNIVERSAL::can($object, "attributes") and scalar @{$object->attributes;}
MC/DC100%1/1
UNIVERSAL::can($object, "attributes") and scalar @{$object->attributes;}
UNIVERSAL::can($object, "attributes")
Truth table100%2/2
A
A= UNIVERSAL::can($object, "attributes")
| |||||||||||||||||||||||||||||
| 474 | 5 | my $attributes = $object->attributes(); | |||||||||||||||||||||||||||
| 475 | 5 | my $attribPfx = ""; | |||||||||||||||||||||||||||
| 476 | 5 | ▶ | $attribPfx = $object->attributePrefix() if (UNIVERSAL::can($object, "attributePrefix")); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | 5 | my $attribInfo = $object->effectiveAttributeInfo(); | |||||||||||||||||||||||||||
| 478 | 5 | ▶ | my $elementInfo = UNIVERSAL::can($object, 'effectiveElementInfo') ? $object->effectiveElementInfo() : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 5 | $pod .= "\n\n=head1 ATTRIBUTE ACCESSORS\n"; | |||||||||||||||||||||||||||
| 481 | 5 | $pod .= "\n=over\n"; | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 5 | foreach my $attribute_name (sort @$attributes) { | |||||||||||||||||||||||||||
| 484 | 7 | my $accessor = $attribPfx . $attribute_name; | |||||||||||||||||||||||||||
| 485 | 7 | my $attrib = $attribInfo->{$attribute_name}; | |||||||||||||||||||||||||||
| 486 | 7 | ▶ | next unless (defined $attrib); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 7 | $pod .= "\n=item B<$accessor>()"; | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | # Attribute accessor alias (if there is no conflict with an element name) | ||||||||||||||||||||||||||||
| 491 | 7 | ▶ | unless (exists($elementInfo->{$attribute_name})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 7 | $pod .= ", B<$attribute_name>()"; | |||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | 7 | my $aclass = $attrib->class; | |||||||||||||||||||||||||||
| 496 | 7 | ▶ | if (defined $aclass) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | 7 | $pod .= " - See L<$aclass>."; | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 7 | $pod .= "\n"; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | 5 | $pod .= "\n=back\n"; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | # CHILD ELEMENT accessors | ||||||||||||||||||||||||||||
| 507 | 15 | ▶ | if (UNIVERSAL::can($object, "elements") && scalar(@{$object->elements})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
UNIVERSAL::can($object, "elements") and scalar @{$object->elements;}
MC/DC100%1/1
UNIVERSAL::can($object, "elements") and scalar @{$object->elements;}
UNIVERSAL::can($object, "elements")
Truth table100%2/2
A
A= UNIVERSAL::can($object, "elements")
| |||||||||||||||||||||||||||||
| 508 | 2 | my $elementInfo = $object->effectiveElementInfo(); | |||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 2 | $pod .= "\n\n=head1 CHILD ELEMENT ACCESSORS\n"; | |||||||||||||||||||||||||||
| 511 | 2 | $pod .= "\n=over\n"; | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 2 | foreach my $accessor (sort @{$object->elements()}) { | |||||||||||||||||||||||||||
| 514 | 6 | my $element = $elementInfo->{$accessor}; | |||||||||||||||||||||||||||
| 515 | 6 | ▶ | next unless (defined $element); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 6 | $pod .= "\n=item B<$accessor>()"; | |||||||||||||||||||||||||||
| 518 | 6 | my $aclass = $element->class; | |||||||||||||||||||||||||||
| 519 | 6 | ▶ | if (defined $aclass) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 520 | 6 | $pod .= " - See L<$aclass>."; | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 6 | $pod .= "\n"; | |||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | 2 | $pod .= "\n=back\n"; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | # SEE ALSO | ||||||||||||||||||||||||||||
| 530 | 15 | my @see_also = (@$isa, 'XML::Pastor', 'XML::Pastor::Type', 'XML::Pastor::ComplexType', 'XML::Pastor::SimpleType'); | |||||||||||||||||||||||||||
| 531 | 15 | @see_also = map {"L<$_>"} @see_also; | |||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | 15 | $pod .= "\n\n=head1 SEE ALSO\n\n"; | |||||||||||||||||||||||||||
| 534 | 15 | $pod .= join (", ", @see_also); | |||||||||||||||||||||||||||
| 535 | 15 | $pod .= "\n"; | |||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | # EPILOGUE | ||||||||||||||||||||||||||||
| 538 | 15 | $pod .= "\n\n=cut\n"; | |||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 15 | return $pod; | |||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 546 | # Dump the data for a given "schema type". | ||||||||||||||||||||||||||||
| 547 | # Note the use of "Deepcopy" and "Terse" | ||||||||||||||||||||||||||||
| 548 | # in order to avoid having references in the dumped structure. | ||||||||||||||||||||||||||||
| 549 | # So we have a clean structure with eventual duplication of data but witout references. | ||||||||||||||||||||||||||||
| 550 | 162 | ▶ | sub _dumpObject { | ||||||||||||||||||||||||||
|
Subroutine
_dumpObject: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 551 | 158 | my $object = shift; | |||||||||||||||||||||||||||
| 552 | 158 | my $d = Data::Dumper->new([$object]); | |||||||||||||||||||||||||||
| 553 | 158 | $d->Sortkeys(1); | |||||||||||||||||||||||||||
| 554 | 158 | $d->Deepcopy(1); | |||||||||||||||||||||||||||
| 555 | 158 | $d->Terse(1); | |||||||||||||||||||||||||||
| 556 | 158 | return $d->Dump(); | |||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | #-------------------------------------------- | ||||||||||||||||||||||||||||
| 560 | # Write a chunk of code onto a given file. | ||||||||||||||||||||||||||||
| 561 | # Used for writing out the code to the output module files. | ||||||||||||||||||||||||||||
| 562 | # Works for both 'single' and 'multiple' style | ||||||||||||||||||||||||||||
| 563 | 19 | ▶ | sub _writeCode { | ||||||||||||||||||||||||||
|
Subroutine
_writeCode: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||
| 564 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 565 | 17 | my $args = {@_}; | |||||||||||||||||||||||||||
| 566 | 17 | ▶ | my $code = $args->{code} || ""; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'code'} || ''
MC/DC0%0/1
$args->{'code'} || ''
$args->{'code'}
Truth table50%1/2
A
A= $args->{'code'}
| |||||||||||||||||||||||||||||
| 567 | 17 | ▶ | my $file = $args->{file} or die "Pastor : Generator : _writeCode : requires a file name\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 17 | ▶ | my $verbose = $self->{verbose} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'verbose'} || 0
MC/DC0%0/1
$self->{'verbose'} || 0
$self->{'verbose'}
Truth table50%1/2
A
A= $self->{'verbose'}
| |||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 17 | ▶ | print STDERR "\nWriting module '$file' ..." if ($verbose >=2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 571 | 17 | my ($volume,$directories,$filebase) = File::Spec->splitpath( $file ); | |||||||||||||||||||||||||||
| 572 | 17 | File::Path::mkpath($volume.$directories); | |||||||||||||||||||||||||||
| 573 | 17 | ▶ | my $handle = IO::File->new($file, "w") or die "Pastor : Generator : _writeCode : Can't open file : $file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 17 | print $handle $code; | |||||||||||||||||||||||||||
| 576 | 17 | $handle->close(); | |||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 10 | 1; | |||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | __END__ | ||||||||||||||||||||||||||||