File Coverage

blib/lib/OpenFeature/SDK.pm
Criterion Covered Total %
statement 29 65 44.6
branch 2 4 50.0
condition n/a
subroutine 7 15 46.6
pod 0 11 0.0
total 38 95 40.0


line stmt bran cond sub pod time code
1 1     1   136631 use v5.36;
  1         3  
2             package OpenFeature::SDK v0.1.1;
3              
4 1     1   321 use OpenFeature::ProviderRegistry;
  1         3  
  1         25  
5 1     1   366 use OpenFeature::Client;
  1         2  
  1         26  
6 1     1   341 use OpenFeature::EvaluationContext;
  1         3  
  1         311  
7              
8             =encoding UTF-8
9              
10             =head1 NAME
11              
12             OpenFeature::SDK - OpenFeature SDK for Perl
13              
14             =head1 SYNOPSIS
15              
16             use v5.36;
17             use OpenFeature::SDK;
18             my $openfeature_sdk = OpenFeature::SDK->new();
19             $openfeature_sdk->set_provider($someProvider, 'someDomain');
20             my $openfeature_client = $openfeature_sdk->get_client('someDomain');
21             my $boolean_flag = $openfeature_client->get_boolean_value('flagName', 0);
22              
23             =head1 DESCRIPTION
24              
25             The future of feature flagging is here! Which is an assortment of functions to
26             call L to
27             get your flag details out.
28              
29             OpenFeature provides 5 distinct types of flags in: "Boolean", "String",
30             "Integer", "Float" and "Object". The job of this SDK package is to provider the
31             global configuration layer and access to the underlying L
32             package.
33              
34             =cut
35              
36 1     1 0 167891 sub new($class) {
  1         3  
  1         1  
37 1         3 my $self = {};
38 1         6 $self->{'provider_registry'} = OpenFeature::ProviderRegistry->new();
39 1         7 $self->{'evaluation_context'} = OpenFeature::EvaluationContext->new({});
40 1         6 bless $self, $class
41             }
42              
43 3     3 0 11 sub set_provider($self, $provider, $domain = undef) {
  3         3  
  3         4  
  3         3  
  3         3  
44             defined $domain
45             ? $self->{'provider_registry'}->set_provider($domain, $provider)
46 3 100       27 : $self->{'provider_registry'}->set_default_provider($provider)
47             }
48              
49 0     0 0 0 sub clear_providers($self) {
  0         0  
  0         0  
50 0         0 $self->{'provider_registry'}->clear_providers()
51             }
52              
53 1     1 0 2 sub get_client($self, $domain) {
  1         1  
  1         6  
  1         2  
54             OpenFeature::Client->new(
55 1         8 $self->{'provider_registry'},
56             $domain,
57             )
58             }
59              
60 0     0 0   sub get_evaluation_context($self) {
  0            
  0            
61 0           $self->{'evaluation_context'}
62             }
63              
64 0     0 0   sub set_evaluation_context($self, $new_context) {
  0            
  0            
  0            
65 0           $self->{'evaluation_context'} = $new_context
66             }
67              
68 0     0 0   sub get_provider_metadata($self, $domain = undef) {
  0            
  0            
  0            
69             defined $domain
70             ? $self->{'provider_registry'}->get_provider($domain)->get_metadata()
71 0 0         : $self->{'provider_registry'}->get_default_provider()->get_metadata()
72             }
73              
74 0     0 0   sub add_hooks($self, $new_hooks) {
  0            
  0            
  0            
75 0           my $original_hooks = $self->{'hooks'};
76 0           $self->{'hooks'} = [@$original_hooks, @$new_hooks]
77             }
78              
79 0     0 0   sub clear_hooks($self) {
  0            
  0            
80 0           $self->{'hooks'} = []
81             }
82              
83 0     0 0   sub get_hooks($self) {
  0            
  0            
84 0           $self->{'hooks'}
85             }
86              
87 0     0 0   sub shutdown($self) {
  0            
  0            
88 0           $self->{'provider_registry'}->shutdown_all_providers()
89             }
90              
91             1;
92              
93             =head1 Things left to implement
94              
95             =head2 Event handling stuff
96              
97             =over
98              
99             =item * add_handler
100              
101             =item * remove_handler
102              
103             =back
104              
105             =head1 AUTHOR
106              
107             Philipp Böschen
108              
109             =head1 CONTRIBUTORS
110              
111             None so far.
112              
113             =head1 COPYRIGHT
114              
115             Copyright (c) 2024 the OpenFeature::SDK L and L
116             as listed above.
117              
118             =head1 LICENSE
119              
120             This library is free software and may be distributed under the same terms
121             as perl itself. See L.
122              
123             =cut