lib/Language/Zcode/Parser.pm

filter: Statementstmt 100% 24 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 94.2% 33 / 35 CC 3 SCAR 5.6
CC
3
Cov
93%
new
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« lib/Language/Zcode/Translator.pm ↑ Summary lib/Language/Zcode/Runtime/State.pm »
1 package Language::Zcode::Parser;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use Language::Zcode::Parser::Routine;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Language::Zcode::Parser::Opcode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 =head1 NAME
10
11 Language::Zcode::Parser - reads and parses a Z-code file into a big Perl hash
12
13 =head1 SYNOPSIS
14
15 # Create a Pure Perl Parser
16 my $pParser = new Language::Zcode::Parser "Perl";
17
18 # If they didn't put ".z5" at the end, find it anyway
19 $infile = $pParser->find_zfile($infile) || exit;
20
21 # Read in the file, store it in memory
22 $pParser->read_memory($infile);
23
24 # Parse header of the Z-file
25 $pParser->parse_header();
26
27 # Get the subroutines in the file (LZ::Parser::Routine objects)
28 my @subs = $pParser->find_subs($infile);
29
30 =head1 DESCRIPTION
31
32 For finding where the subroutines start and end, you can either depend on
33 an external call to txd, a 1992 C program available at ifarchive.org, or
34 a pure Perl version.
35
36 Everything else is done in pure Perl.
37
38 =cut
39
40 =head2 new (class, how to find subs, args...)
41
42 This is a factory method. Called with 'Perl' or 'TXD' (or 'txd') as arguments,
43 it will create Parsers of LZ::Parser::Perl or LZ::Parser::TXD, which
44 are subclasses of LZ::Parser::Generic.
45
46 That class' 'new' method will be called with any other passed-in args.
47
48 =cut
49
50 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
51 2 my ($class, $sub_finder, @arg) = @_;
52 # XXX I'll bet there's some fancy way of telling if a class exists.
53 # E.g., test $class->can("new")
54 2 ▶ die "Arg for how to find subs must be 'Perl' or 'txd', not '$sub_finder\n'"
Branch: 1 branch
BranchTrueFalseTotal
unless $sub_finder =~ /^(perl|txd)$/i 0 2 2
55 unless $sub_finder =~ /^(perl|txd)$/i;
56 2 $sub_finder =~ s/perl/Perl/i;
57 2 $sub_finder =~ s/txd/TXD/i;
58 2 my $new_class = "Language::Zcode::Parser::${sub_finder}";
59 2 ▶ eval "use $new_class"; die $@ if $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
60 2 return new $new_class @arg;
61 }
62
63 2 1;
« lib/Language/Zcode/Translator.pm ↑ Summary lib/Language/Zcode/Runtime/State.pm »