File Coverage

blib/lib/Pass/OTP/URI.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Pass::OTP::URI;
2              
3             =encoding utf8
4              
5             =head1 NAME
6              
7             Pass::OTP::URI - Parse otpauth:// URI
8              
9             =head1 SYNOPSIS
10              
11             use Pass::OTP::URI qw(parse);
12              
13             my $uri = "otpauth://totp/ACME:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME&digits=6";
14             my %options = parse($uri);
15              
16             =cut
17              
18 1     1   1393 use utf8;
  1         2  
  1         14  
19 1     1   45 use strict;
  1         2  
  1         24  
20 1     1   6 use warnings;
  1         2  
  1         311  
21              
22             require Exporter;
23             our @ISA = qw(Exporter);
24             our @EXPORT_OK = qw(parse);
25              
26             =head1 FUNCTIONS
27              
28             =over 4
29              
30             =item parse($uri)
31              
32             =cut
33              
34             sub parse {
35 2     2 1 1163 my ($uri) = @_;
36              
37 2         5 my %options = (
38             base32 => 1,
39             );
40 2         19 ($options{type}, $options{label}, my $params) = $uri =~ m#^otpauth://([th]otp)/((?:[^:?]+(?::|%3A))?[^:?]+)\?(.*)#;
41              
42 2         8 foreach my $param (split(/&/, $params)) {
43 4         11 my ($option, $value) = split(/=/, $param);
44 4         9 $options{$option} = $value;
45             }
46              
47 2         15 return (%options);
48             }
49              
50             =back
51              
52             =head1 SEE ALSO
53              
54             L
55              
56             L
57              
58             =head1 COPYRIGHT AND LICENSE
59              
60             Copyright (C) 2020 Jan Baier
61              
62             This program is free software; you can redistribute it and/or modify it
63             under the terms of either: the GNU General Public License as published
64             by the Free Software Foundation; or the Artistic License.
65              
66             See L for more information.
67              
68             =cut
69              
70             1;