blib/lib/Text/KDL/XS.pm

filter: Statementstmt 100% 57 / 57 Branchbran 100% 14 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 100% 88 / 88 CC 8 SCAR 7.4
CC
8
Cov
100%
_parse_named_arguments
4.0
_normalize_version
3.0
_rethrow
3.0
CRAP 2.1
« blib/lib/Text/KDL/XS/Node.pm ↑ Summary ckdl/src/str.c »
1 package Text::KDL::XS;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 our $VERSION;
7  
8 # The XS code is loaded before the class modules below are compiled, so that
9 # each of them can also be loaded on its own (they all load this module).
10 24 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 $VERSION = '0.003';
12 24 require XSLoader;
13 24 XSLoader::load(__PACKAGE__, $VERSION);
14 }
15  
16 24 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 24 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 24 ▶use Text::KDL::XS::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 24 ▶use Text::KDL::XS::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 24 ▶use Text::KDL::XS::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 24 ▶use Text::KDL::XS::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 24 ▶use Text::KDL::XS::Emitter;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 24 our @EXPORT_OK = qw(parse_kdl emit_kdl);
26  
27 # Errors raised anywhere in the distribution are reported at the caller's line.
28 24 our @CARP_NOT = qw(
29 Text::KDL::XS::Document Text::KDL::XS::Emitter Text::KDL::XS::Node
30 Text::KDL::XS::Parser Text::KDL::XS::Value
31 );
32  
33 24 my %VERSION_BY_NAME = (detect => 'detect', 1 => 1, 2 => 2, v1 => 1, v2 => 2);
34  
35 158 ▶sub parse_kdl {
Subroutine parse_kdl: called CC=1 SCAR=0.0
Pod documented
36 158 my ($source, @options) = @_;
37 158 my $parser = Text::KDL::XS::Parser->new($source, @options);
38 147 return Text::KDL::XS::Document->_build_from_parser($parser);
39 }
40  
41 165 ▶sub emit_kdl {
Subroutine emit_kdl: called CC=1 SCAR=0.0
Pod documented
42 165 my ($tree, @options) = @_;
43 165 return Text::KDL::XS::Emitter->_emit_tree($tree, @options);
44 }
45  
46 # The KDL version selected by a version option: 'detect', 1 or 2. Accepts
47 # detect, 1, 2, v1 and v2 in any letter case; undef means detect.
48 337 ▶sub _normalize_version {
Subroutine _normalize_version: called CC=3 SCAR=11.0
49 337 my ($who, $version) = @_;
50 337 ▶ return 'detect' unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 229 108 337
51 108 my $normalized = $VERSION_BY_NAME{ lc $version };
52 108 ▶ Carp::croak("$who: unknown version '$version' (expected 'detect', '1' or '2')")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $normalized 4 104 108
53 unless defined $normalized;
54 104 return $normalized;
55 }
56  
57 # A hash reference of name => value pairs whose names are all allowed. $noun
58 # ('option' or 'field') names them in the error message.
59 673 ▶sub _parse_named_arguments {
Subroutine _parse_named_arguments: called CC=4 SCAR=13.9
60 673 my ($who, $noun, $allowed, @pairs) = @_;
61 673 ▶ Carp::croak("$who: expected name => value pairs, got an odd number of arguments") if @pairs % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @pairs % 2 2 671 673
62 671 my %arguments = @pairs;
63 671 my @unknown = sort grep { !$allowed->{$_} } keys %arguments;
64 671 ▶ Carp::croak("$who: unknown $noun" . (@unknown == 1 ? '' : 's') . ' ' . join ', ', map {"'$_'"} @unknown)
Branch: 2 branches
BranchTrueFalseTotal
if @unknown 2 669 671
@unknown == 1 ? : 1 1 2
65 if @unknown;
66 669 return \%arguments;
67 }
68  
69 # Raises an error caught around a call into the XS code again. The XS code
70 # reports errors at the line of $file that called it; such errors are raised
71 # again at the user's call site. Errors thrown by user code (source callbacks)
72 # and exception objects pass through unchanged.
73 68 ▶sub _rethrow {
Subroutine _rethrow: called CC=3 SCAR=11.0
74 68 my ($error, $file) = @_;
75 68 ▶ die $error if ref $error;
Branch: 1 branch
BranchTrueFalseTotal
if ref $error 1 67 68
76 67 ▶ die $error unless $error =~ s/ at \Q$file\E line \d+(?:, <[^>]*> (?:line|chunk) \d+)?\.\n\z//;
Branch: 1 branch
BranchTrueFalseTotal
unless $error =~ s/ at \Q$file\E line \d+(?:, <[^>]*> (?:line|chunk) \d+)?\.\n\z// 12 55 67
77 55 Carp::croak($error);
78 }
79  
80 24 1;
81  
82 __END__
« blib/lib/Text/KDL/XS/Node.pm ↑ Summary ckdl/src/str.c »