MetaPOD/Assembler.pm

filter: Statementstmt 77.5% 45 / 58 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 12 / 16 Podpod 100% 5 / 5 totaltotal 77.1% 64 / 83 CC 3 SCAR 3.4
CC
3
Cov
76%
get_class_for_format
2.1
handle_segment
2.0
_build_format_map
2.0
CRAP 1.4
« MetaPOD/Result.pm ↑ Summary MetaPOD/Exception/Decode/Data.pm »
1 2 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package MetaPOD::Assembler;
6  
7 2 our $VERSION = 'v0.4.0';
8  
9 # ABSTRACT: Glue layer that dispatches segments to a constructed Result
10  
11 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45 2 ▶use Moo qw( has );
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49  
50  
51  
52  
53 has 'result' => (
54 is => ro =>,
55 required => 0,
56 lazy => 1,
57 2 ▶ builder => sub {
Subroutine _build_result: called CC=1 SCAR=0.0
58 2 require MetaPOD::Result;
59 2 return MetaPOD::Result->new();
60 },
61 2 clearer => 'clear_result',
62 );
63  
64  
65  
66  
67  
68 has extractor => (
69 is => ro =>,
70 required => 1,
71 lazy => 1,
72 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=1 SCAR=0.5
Subroutine _build_extractor: called CC=1 SCAR=0.5
73 0 my $self = shift;
74 0 require MetaPOD::Extractor;
75 return MetaPOD::Extractor->new(
76 1 ▶ end_segment_callback => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 1 my $segment = shift;
78 1 $self->handle_segment($segment);
79 },
80 0 );
81 },
82 2 );
83  
84  
85  
86  
87  
88 has format_map => (
89 is => ro =>,
90 required => 1,
91 lazy => 1,
92 0 ▶ builder => sub {
Subroutine _build_format_map: not called CC=1 SCAR=6.9
93 0 return { 'JSON' => 'MetaPOD::Format::JSON', };
94 },
95 2 );
96  
97  
98  
99  
100  
101  
102  
103 0 ▶sub assemble_handle {
Subroutine assemble_handle: not called CC=1 SCAR=6.9
Pod documented
104 0 my ( $self, $handle ) = @_;
105 0 $self->clear_result;
106 0 $self->extractor->read_handle($handle);
107 0 return $self->result;
108 }
109  
110  
111  
112  
113  
114  
115  
116 1 ▶sub assemble_file {
Subroutine assemble_file: called CC=1 SCAR=0.0
Pod documented
117 1 my ( $self, $file ) = @_;
118 1 $self->clear_result;
119 1 $self->extractor->read_file($file);
120 1 return $self->result;
121 }
122  
123  
124  
125  
126  
127  
128  
129 0 ▶sub assemble_string {
Subroutine assemble_string: not called CC=1 SCAR=6.9
Pod documented
130 0 my ( $self, $string ) = @_;
131 0 $self->clear_result;
132 0 $self->extractor->read_string($string);
133 0 return $self->result;
134 }
135  
136  
137  
138  
139  
140  
141  
142 1 ▶sub get_class_for_format {
Subroutine get_class_for_format: called CC=2 SCAR=7.6
Pod documented
143 1 my ( $self, $format ) = @_;
144 1 ▶ if ( not exists $self->format_map->{$format} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->format_map->{$format}) 0 1 1
145 0 croak "format $format unsupported";
146 }
147 1 return $self->format_map->{$format};
148 }
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163 1 ▶sub handle_segment {
Subroutine handle_segment: called CC=2 SCAR=7.0
Pod documented
164 1 my ( $self, $segment ) = @_;
165 1 my $format = $segment->{format};
166 1 my $version = $segment->{version};
167  
168 1 my $class = $self->get_class_for_format($format);
169 1 use_module($class);
170  
171 1 ▶ return unless $class->supports_version($version);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->supports_version($version) 0 1 1
172  
173 1 $class->add_segment( $segment, $self->result );
174  
175 1 return $self;
176 }
177  
178 2 1;
179  
180 __END__
« MetaPOD/Result.pm ↑ Summary MetaPOD/Exception/Decode/Data.pm »