File Coverage

lib/User/Information.pm
Criterion Covered Total %
statement 29 46 63.0
branch 0 6 0.0
condition 0 6 0.0
subroutine 10 15 66.6
pod 4 4 100.0
total 43 77 55.8


line stmt bran cond sub pod time code
1             # Copyright (c) 2025 Philipp Schafft
2              
3             # licensed under Artistic License 2.0 (see LICENSE file)
4              
5             # ABSTRACT: generic module for extracting information from user accounts
6              
7              
8             package User::Information;
9              
10 1     1   382086 use v5.20;
  1         5  
11 1     1   6 use strict;
  1         2  
  1         88  
12 1     1   11 use warnings;
  1         2  
  1         67  
13              
14 1     1   6 use Carp;
  1         1  
  1         96  
15 1     1   1066 use Data::Identifier;
  1         196018  
  1         8  
16              
17 1     1   104 use parent qw(Data::Identifier::Interface::Known);
  1         2  
  1         12  
18              
19             use constant {
20 1         5 SPECIAL_ME => [],
21             SPECIAL_CGI => [],
22             SPECIAL_LOCAL_NODE => Data::Identifier->new(uuid => '081c3899-cc4f-4cbd-9590-c90d1321e24c')->register,
23 1     1   131 };
  1         1  
24              
25 1     1   809 use constant PATH_ELEMENT_NS => Data::Identifier->new(uuid => '533fd060-2b96-4aea-8b8d-56e0766e6e5d')->register;
  1         3  
  1         4  
26 1         5 use constant PATH_ELEMENT_TYPE => Data::Identifier->new(
27             uuid => 'f1f59629-3237-4587-a365-7ce094806f6d',
28             displayname => 'user-information-path-element',
29             validate => qr/^[0-9a-zA-Z_-]+$/,
30             namespace => PATH_ELEMENT_NS,
31 1     1   758 )->register;
  1         1  
32              
33 1     1   1441 use User::Information::Base;
  1         5  
  1         258  
34              
35             our $VERSION = v0.05;
36              
37              
38             #@returns User::Information::Base
39             sub lookup {
40 0     0 1   my ($self, @args) = @_;
41 0           my ($type, $request);
42              
43 0 0         if (scalar(@args) & 1) {
44 0           $type = 'from';
45             } else {
46 0   0       $type = shift(@args) // croak 'No type given';
47             }
48 0   0       $request = shift(@args) // croak 'No request given';
49              
50 0           return User::Information::Base->_new($type => $request, @args);
51             }
52              
53              
54             #@returns User::Information::Base
55             sub me {
56 0     0 1   my ($self, %opts) = @_;
57 0           return $self->lookup(from => SPECIAL_ME, %opts);
58             }
59              
60              
61             sub cgi {
62 0     0 1   my ($self, %opts) = @_;
63              
64 0           return $self->lookup(from => SPECIAL_CGI, %opts);
65             }
66              
67              
68             #@returns User::Information::Base
69             sub local_node {
70 0     0 1   my ($self, %opts) = @_;
71 0           return state $local_node = $self->lookup(from => SPECIAL_LOCAL_NODE, %opts);
72             }
73              
74              
75             # ---- Private helpers ----
76             sub _known_provider {
77 0     0     my ($self, $class, %opts) = @_;
78              
79 0 0         croak 'Unsupported options passed' if scalar(keys %opts);
80              
81 0 0         return [SPECIAL_LOCAL_NODE, PATH_ELEMENT_NS, PATH_ELEMENT_TYPE], rawtype => 'Data::Identifier' if $class eq ':all';
82              
83 0           croak 'Unknown class';
84             }
85              
86             1;
87              
88             __END__