| 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
| |||||||||||
| 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
| |||||||||||
| 32 | 1 | return new $new_class @arg; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 1 | 1; | |||||||||
| 36 | |||||||||||