blib/lib/App/QRCodeUtils.pm

filter: Statementstmt 50.0% 16 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 45.6% 21 / 46 CC 4 SCAR 23.6
CC
4
Cov
42%
gen_qrcode
20.0
decode_qrcode
2.0
BEGIN
1.0
CRAP 10.6
↑ Summary
1 package App::QRCodeUtils;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 1 our $DATE = '2026-01-20'; # DATE
9 1 our $DIST = 'App-QRCodeUtils'; # DIST
10 1 our $VERSION = '0.005'; # VERSION
11  
12 1 our %SPEC;
13  
14 $SPEC{decode_qrcode} = {
15 1 v => 1.1,
16 summary => 'Decode QR Code',
17 args => {
18 filename => {
19 schema => 'filename*',
20 req => 1,
21 pos => 0,
22 },
23 },
24 examples => [
25 ],
26 };
27 0 ▶sub decode_qrcode {
Subroutine decode_qrcode: not called CC=1 SCAR=6.9
Pod documented
28 0 return [500, "Currently Image::DecodeQR cannot be built"];
29  
30 #require Image::DecodeQR;
31  
32 0 my %args = @_;
33  
34 0 my $str = Image::DecodeQR::decode($args{filename});
35  
36 0 [200, "OK", $str];
37 }
38  
39 $SPEC{gen_qrcode} = {
40 1 v => 1.1,
41 summary => 'Generate QR Code and by default show it (or save it to a file)',
42 args => {
43 text => {
44 schema => 'str*',
45 req => 1,
46 pos => 0,
47 },
48 filename => {
49 schema => 'filename*',
50 pos => 1,
51 description => <<'MARKDOWN',
52  
53 If unspecified, will save to a temporary filename and show it with
54 <pm:Desktop::Open>.
55  
56 MARKDOWN
57 },
58 format => {
59 schema => ['str*', in=>[qw/png html txt/]],
60 default => 'png',
61 },
62 level => {
63 summary => 'Error correction level',
64 schema => ['str*', in=>['L', 'M', 'Q', 'H']],
65 default => 'M',
66 },
67 },
68 examples => [
69 ],
70 };
71 0 ▶sub gen_qrcode {
Subroutine gen_qrcode: not called CC=4 SCAR=30.0
Pod documented
72 0 require QRCode::Any;
73  
74 0 my %args = @_;
75 0 ▶ my $format = $args{format} // 'png';
Condition0%0/2
$args{"format"} // "png"
l!l
00
MC/DC0%0/1
$args{"format"} // "png"
$args{"format"}
Truth table0%0/2
A
A= $args{"format"}
Aresult
11
00
76  
77 0 my $filename = $args{filename};
78 0 ▶ unless (defined $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
79 0 require File::Temp;
80 0 (undef, $filename) = File::Temp::tempfile("qrcodeXXXXXXXXX", TMPDIR=>1, SUFFIX=>".$format");
81 }
82  
83 my $res = QRCode::Any::encode_qrcode(
84 format => $format,
85 text => $args{text},
86 filename => $filename,
87 level => $args{level},
88 0 );
89 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
90  
91 0 require Desktop::Open;
92 0 Desktop::Open::open_desktop($filename);
93  
94 0 [200, "OK", undef, {"func.filename"=>$filename}];
95 }
96  
97 1 1;
98 # ABSTRACT: Utilities related to QR Code
99  
100 __END__
↑ Summary