lib/Language/Zcode/Translator.pm

filter: Statementstmt 100% 24 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 91.4% 32 / 35 CC 3 SCAR 5.7
CC
3
Cov
93%
new
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« script/plotz.pl ↑ Summary lib/Language/Zcode/Parser.pm »
1 package Language::Zcode::Translator;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 # XXX For some reason, Constants & Memory aren't getting imported
7 # (But importing %Constants into PlotzParse works!)
8 1 ▶use Language::Zcode::Util qw(%Constants @Memory);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Language::Zcode::Translator::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 =head1 Language::Zcode::Translator
12
13 This class is just a factory. It figure out which subclass of
14 Language::Zcode::Translator::Generic we want to use. It then
15 loads that class, and creates a translator object of that class.
16
17 A translator object has methods to translate Z-code into a given language.
18 See L<Language::Zcode::Translator::Generic>.
19
20 =cut
21
22 1 my %known_languages = map {$_=>1} qw(Perl PIR XML);
23
24 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
25 1 my ($class, $language, @arg) = @_;
26 # XXX I'll bet there's some fancy way of telling if a class exists.
27 # E.g., test $class->can("new")
28 1 ▶ die"Unknown language $language\n" unless exists $known_languages{$language};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $known_languages{$language} 0 1 1
29 1 my $new_class = "Language::Zcode::Translator::$language";
30 # Include the necessary translator code or die()
31 1 ▶ eval "use $new_class"; die "$@\n" if $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
32 1 return new $new_class @arg;
33 }
34
35 1 1;
36
« script/plotz.pl ↑ Summary lib/Language/Zcode/Parser.pm »