blib/lib/ExtUtils/Builder/Serializer.pm

filter: Statementstmt 91.8% 56 / 61 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 100% 8 / 8 totaltotal 90.0% 81 / 90 CC 6 SCAR 5.3
CC
6
Cov
88%
deserialize_action
3.3
serialize_action
2.0
serialize_plan
2.0
CRAP 1.7
« blib/lib/ExtUtils/Builder/FileSet.pm ↑ Summary blib/lib/ExtUtils/Builder/Action.pm »
1 package ExtUtils::Builder::Serializer;
2 2 $ExtUtils::Builder::Serializer::VERSION = '0.020';
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 Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use ExtUtils::Builder::Action::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use ExtUtils::Builder::Action::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use ExtUtils::Builder::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use ExtUtils::Builder::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶sub serialize_plan {
Subroutine serialize_plan: called CC=2 SCAR=6.9
Pod documented
14 1 my ($self, $plan) = @_;
15  
16 1 my %nodes;
17 1 for my $node_name ($plan->node_names) {
18 4 $nodes{$node_name} = $self->serialize_node($plan->node($node_name));
19 }
20  
21 return {
22 1 nodes => \%nodes,
23 }
24 }
25  
26 4 ▶sub serialize_node {
Subroutine serialize_node: called CC=1 SCAR=0.0
Pod documented
27 4 my ($self, $node, %opts) = @_;
28 4 my @actions = map { $self->serialize_action($_, %opts) } $node->flatten;
29 return {
30 4 dependencies => [ $node->dependencies ],
31 actions => \@actions,
32 type => $node->type,
33 }
34 }
35  
36 3 ▶sub serialize_action {
Subroutine serialize_action: called CC=2 SCAR=7.0
Pod documented
37 3 my ($self, $action, %opts) = @_;
38 3 my $preference = $action->preference('code', 'command');
39 3 ▶ my $method = $preference eq 'code' ? 'serialize_code' : 'serialize_command';
Branch: 1 branch
BranchTrueFalseTotal
$preference eq 'code' ? : 3 0 3
40 3 return $self->$method($action, %opts);
41 }
42  
43 3 ▶sub serialize_code {
Subroutine serialize_code: called CC=1 SCAR=0.0
Pod documented
44 3 my ($self, $action, %opts) = @_;
45 3 return [ 'code', $action->to_code_hash(%opts) ];
46 }
47  
48 0 ▶sub serialize_command {
Subroutine serialize_command: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($self, $action, %opts) = @_;
50 0 return map { [ 'command', $_ ] } $action->to_command(%opts)
51 }
52  
53  
54 1 ▶sub deserialize_plan {
Subroutine deserialize_plan: called CC=2 SCAR=6.9
Pod documented
55 1 my ($self, $serialized, %options) = @_;
56  
57 1 my %nodes;
58 1 for my $node_name (keys %{ $serialized->{nodes} }) {
59 4 $nodes{$node_name} = $self->deserialize_node($node_name, $serialized->{nodes}{$node_name}, %options);
60 }
61  
62 1 return ExtUtils::Builder::Plan->new(
63 nodes => \%nodes,
64 );
65 }
66  
67 4 ▶sub deserialize_node {
Subroutine deserialize_node: called CC=1 SCAR=0.0
Pod documented
68 4 my ($self, $name, $serialized, %options) = @_;
69  
70 4 my @actions = map { $self->deserialize_action($_, %options) } @{ $serialized->{actions} };
71  
72 return ExtUtils::Builder::Node->new(
73 target => $name,
74 4 dependencies => [ @{ $serialized->{dependencies} } ],
75 actions => \@actions,
76 type => $serialized->{type},
77 4 );
78 }
79  
80 3 ▶sub deserialize_action {
Subroutine deserialize_action: called CC=3 SCAR=12.0
Pod documented
81 3 my ($self, $serialized, %options) = @_;
82 3 my ($command, @args) = @{$serialized};
83  
84 3 ▶ if ($command eq 'command') {
Branch: 2 branches
BranchTrueFalseTotal
if ($command eq 'command') { } 0 3 3
elsif ($command eq 'code') { } 3 0 3
85 0 return ExtUtils::Builder::Action::Command->new(command => $args[0]);
86 } elsif ($command eq 'code') {
87 3 return map { ExtUtils::Builder::Action::Code->new(%$_) } @args;
88 } else {
89 0 croak "Unknown serialized command $command";
90 }
91 }
92  
93 2 1;
94  
95 #ABSTRACT:
96  
97 __END__
« blib/lib/ExtUtils/Builder/FileSet.pm ↑ Summary blib/lib/ExtUtils/Builder/Action.pm »