Htpasswd.pm

filter: Statementstmt 100% 38 / 38 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 89.5% 60 / 67 CC 7 SCAR 11.0
CC
7
Cov
90%
new
6.3
user_supports
2.1
BEGIN
1.0
CRAP 3.0
↑ Summary Htpasswd/User.pm »
1 #!/usr/bin/perl
2  
3 package Catalyst::Authentication::Store::Htpasswd; # git description: v1.005-4-g2915058
4 # ABSTRACT: Authen::Htpasswd based user storage/authentication
5  
6 4 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Authen::Htpasswd 0.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Catalyst::Authentication::Store::Htpasswd::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 our $VERSION = '1.006';
15  
16 4 ▶BEGIN { __PACKAGE__->mk_accessors(qw/file user_field user_class/) }
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶sub new {
Subroutine new: called CC=6 SCAR=18.4
Pod documented
19 3 my ($class, $config, $app, $realm) = @_;
20  
21 3 my $file = delete $config->{file};
22 3 ▶ unless (ref $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $file) 1 2 3
23 1 ▶ my $filename = ($file =~ m|^/|) ? $file : $app->path_to($file)->stringify;
Branch: 1 branch
BranchTrueFalseTotal
$file =~ m[^/] ? : 0 1 1
24 1 ▶ die("Cannot find htpasswd file: $filename\n") unless (-r $filename);
Branch: 1 branch
BranchTrueFalseTotal
unless -r $filename 0 1 1
25 1 $file = Authen::Htpasswd->new($filename);
26 }
27 3 $config->{file} = $file;
28 3 ▶ $config->{user_class} ||= __PACKAGE__ . '::User';
Condition50%1/2
$config->{"user_class"} ||= "Catalyst::Authentication::Store::Htpasswd::User"
l!l
03
MC/DC0%0/1
$config->{"user_class"} ||= "Catalyst::Authentication::Store::Htpasswd::User"
$config->{"user_class"}
Truth table50%1/2
A
A= $config->{"user_class"}
Aresult
11
00
29 3 ▶ $config->{user_field} ||= 'username';
Condition50%1/2
$config->{"user_field"} ||= "username"
l!l
03
MC/DC0%0/1
$config->{"user_field"} ||= "username"
$config->{"user_field"}
Truth table50%1/2
A
A= $config->{"user_field"}
Aresult
11
00
30  
31 3 bless { %$config }, $class;
32 }
33  
34 4 ▶sub find_user {
Subroutine find_user: called CC=1 SCAR=0.0
Pod documented
35 4 my ($self, $authinfo, $c) = @_;
36 4 my $htpasswd_user = $self->file->lookup_user($authinfo->{$self->user_field});
37 4 $self->user_class->new( $self, $htpasswd_user );
38 }
39  
40 3 ▶sub user_supports {
Subroutine user_supports: called CC=2 SCAR=7.2
Pod documented
41 3 my $self = shift;
42  
43 # this can work as a class method, but in that case you can't have
44 # a custom user class
45 3 ▶ ref($self) ? $self->user_class->supports(@_)
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 3 3
46 : Catalyst::Authentication::Store::Htpasswd::User->supports(@_);
47 }
48  
49 1 ▶sub from_session {
Subroutine from_session: called CC=1 SCAR=0.0
Pod documented
50 1 my ( $self, $c, $id ) = @_;
51 1 $self->find_user( { username => $id } );
52 }
53  
54 4 1;
55  
56 __END__
↑ Summary Htpasswd/User.pm »