File Coverage

blib/lib/OIDC/Client/Trait/HashStore.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package OIDC::Client::Trait::HashStore;
2 3     3   229201 use utf8;
  3         352  
  3         28  
3 3     3   692 use Moose::Role;
  3         533234  
  3         40  
4 3     3   20863 use namespace::autoclean;
  3         7895  
  3         25  
5 3     3   761 use OIDC::Client::Utils qw(reach_data affect_data delete_data);
  3         9  
  3         25  
6              
7             =encoding utf8
8              
9             =head1 NAME
10              
11             OIDC::Client::Trait::HashStore - Moose Trait for hashref stores
12              
13             =head1 DESCRIPTION
14              
15             This Moose Trait automatically adds methods to the instances of the class
16             based on the name of the attribute using it.
17              
18             Used by the C<OIDC::Client::Plugin::session> attribute, it adds read_session(), write_session()
19             and delete_session() methods to the instances of the L<OIDC::Client::Plugin> class.
20              
21             Used by the C<OIDC::Client::Plugin::stash> attribute, it adds read_stash(), write_stash()
22             and delete_stash() methods to the instances of the L<OIDC::Client::Plugin> class.
23              
24             C<read_${name}> method calls the L<OIDC::Client::Utils/"reach_data( $data_tree, \@path, $optional )">
25             function.
26              
27             C<write_${name}> method calls the L<OIDC::Client::Utils/"affect_data( $data_tree, \@path, $value )">
28             function.
29              
30             C<delete_${name}> method calls the L<OIDC::Client::Utils/"delete_data( $data_tree, \@path )">
31             function.
32              
33             =cut
34              
35             after 'install_accessors' => sub {
36             my $self = shift;
37             my $realclass = $self->associated_class();
38             my $name = $self->name;
39 92     92   3309 $realclass->add_method("read_${name}" => sub { return scalar reach_data( $_[0]->$name, $_[1]) });
        92      
40 64     64   3378 $realclass->add_method("write_${name}" => sub { return scalar affect_data($_[0]->$name, $_[1], $_[2]) });
41 10     10   485 $realclass->add_method("delete_${name}" => sub { return scalar delete_data ($_[0]->$name, $_[1]) });
42             };
43              
44             1;