Debian Codegraph @

lib/Test2/Harness/Util/File/JSONL.pm

raw
1 package Test2::Harness::Util::File::JSONL;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.000179';
6
7 use Carp qw/croak/;
8 use Test2::Harness::Util::JSON qw/encode_json decode_json/;
9
10 use parent 'Test2::Harness::Util::File::Stream';
11 use Test2::Harness::Util::HashBase;
12
13 sub decode { shift; decode_json($_[0]) }
14 sub encode { shift; encode_json(@_) . "\n" }
15
16 1;
17
18 __END__
19
20 =pod
21
22 =encoding UTF-8
23
24 =head1 NAME
25
26 Test2::Harness::Util::File::JSONL - Utility class for a JSONL file (stream)
27
28 =head1 DESCRIPTION
29
30 Subclass of L<Test2::Harness::Util::File> and
31 L<Test2::Harness::Util::File::Stream> which automatically handles
32 encoding/decoding JSONL data.
33
34 =head1 SYNOPSIS
35
36 use Test2::Harness::Util::File::JSONL;
37
38 my $jsonl = Test2::Harness::Util::File::JSONL->new(name => '/path/to/file.jsonl');
39
40 while (1) {
41 my @items = $jsonl->poll(max => 1000) or last;
42 for my $item (@items) {
43 ... handle $item ...
44 }
45 }
46
47 or
48
49 use Test2::Harness::Util::File::JSONL;
50
51 my $jsonl = Test2::Harness::Util::File::JSONL->new(name => '/path/to/file.jsonl');
52
53 $jsonl->write({my => 'item', ... });
54 ...
55
56 =head1 SEE ALSO
57
58 See the base classes L<Test2::Harness::Util::File> and
59 L<Test2::Harness::Util::File::Stream> for methods.
60
61 =head1 SOURCE
62
63 The source code repository for Test2-Harness can be found at
64 F<http://github.com/Test-More/Test2-Harness/>.
65
66 =head1 MAINTAINERS
67
68 =over 4
69
70 =item Chad Granum E<lt>[email protected]<gt>
71
72 =back
73
74 =head1 AUTHORS
75
76 =over 4
77
78 =item Chad Granum E<lt>[email protected]<gt>
79
80 =back
81
82 =head1 COPYRIGHT
83
84 Copyright 2020 Chad Granum E<lt>[email protected]<gt>.
85
86 This program is free software; you can redistribute it and/or
87 modify it under the same terms as Perl itself.
88
89 See F<http://dev.perl.org/licenses/>
90
91 =cut