blib/lib/File/SOPS/Comment.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 96.1% 25 / 26 CC 3 SCAR 6.9
CC
3
Cov
100%
BUILD
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/File/SOPS/Format/YAML.pm ↑ Summary blib/lib/File/SOPS/Format/ENV/Ordered.pm »
1 package File::SOPS::Comment;
2 # ABSTRACT: the leaf a sops comment becomes -- not a value, and not a string
3 97 our $VERSION = '0.005';
4 97 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 97 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 97 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 ###############################################################################
9 # The comment leaf (k76, docs/adr/0041)
10 #
11 # sops attaches a comment to the node that FOLLOWS it. Above a mapping key that
12 # stays a `#ENC[...,type:comment]` line, which YAML::XS drops before this
13 # distribution sees a tree; above a SEQUENCE entry there is no comment line to
14 # write, so sops emits the comment as a sequence ENTRY of its own -- in YAML and,
15 # measured, in `--output-type json` as well.
16 #
17 # That entry needs a Perl value that cannot be mistaken for a string, or reading
18 # it puts a value in the caller's list that the file does not contain and a
19 # re-encrypt makes it permanent (k108). This is that value, and it is the
20 # same move type:bool already makes with JSON::PP::Boolean.
21 #
22 # NO OVERLOADED STRINGIFICATION, deliberately. An object that compares equal to
23 # a string slips through every `eq` in this distribution, which is how a comment
24 # became a value in the first place; and detect_type would then have two ways to
25 # answer for the same leaf. ->text is the way to the text.
26 #
27 # This module knows nothing about the wire and loads nothing from this
28 # distribution -- File::SOPS::Encrypted loads IT, which is the direction that
29 # has to hold: the ladder produces the type from this class and
30 # _deserialize_value produces the class from the type, and neither can be
31 # reached from here. k147 moved it out of File/SOPS/Encrypted.pm, where
32 # ADR 0041 first put it, without renaming it.
33 ###############################################################################
34  
35  
36 97 has text => (is => 'ro', required => 1);
37  
38 # required => 1 covers only the missing case. The reference and the empty
39 # string are both defined, so they satisfy `required` and have to be refused
40 # here, once the attribute is set -- BUILD runs after that. The messages are
41 # the ones the hand-written constructor raised before this class became Moo
42 # (docs/adr/0068); t/56 reads the empty-string one.
43 73 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
44 73 my ($self) = @_;
45 73 my $text = $self->text;
46  
47 73 ▶ croak "a comment's text is a string, not a " . ref($text) . " reference"
Branch: 1 branch
BranchTrueFalseTotal
if ref $text 1 72 73
48 if ref $text;
49  
50 # Measured against sops 3.13.3: a bare `#` above a sequence entry is
51 # written as an UNENCRYPTED empty string element (`- ""`) and no comment
52 # leaf at all, so type:comment never carries an empty plaintext. Refused
53 # here rather than three layers down in encrypt_value, whose message is
54 # about GCM ciphertext length and says nothing about comments.
55 72 ▶ croak "a comment's text cannot be empty: AES-GCM ciphertext is the length "
Branch: 1 branch
BranchTrueFalseTotal
unless length $text 1 71 72
56 . "of its plaintext, so there is no ENC[...] to write -- and sops "
57 . "itself writes an empty comment as an empty string element rather "
58 . "than as a comment"
59 unless length $text;
60  
61 71 return;
62 }
63  
64  
65  
66  
67 97 1;
68  
69 __END__
« blib/lib/File/SOPS/Format/YAML.pm ↑ Summary blib/lib/File/SOPS/Format/ENV/Ordered.pm »