File Coverage

blib/lib/Catalyst/Model/LDAP/FromAuthentication.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 4 0.0
condition 0 4 0.0
subroutine 5 6 83.3
pod 0 1 0.0
total 19 37 51.3


line stmt bran cond sub pod time code
1             package Catalyst::Model::LDAP::FromAuthentication;
2 1     1   843 use Moose;
  1         297321  
  1         6  
3 1     1   5190 use Catalyst::Model::LDAP::Connection;
  1         124580  
  1         6  
4 1     1   458 use Catalyst::Model::LDAP::Entry;
  1         499  
  1         6  
5 1     1   38 use 5.005003;
  1         4  
6 1     1   448 use namespace::autoclean;
  1         5932  
  1         4  
7              
8             our $VERSION = '0.00_01';
9             $VERSION = eval $VERSION;
10              
11             extends qw/Catalyst::Model::LDAP/;
12              
13             with 'Catalyst::Component::InstancePerContext';
14              
15             after COMPONENT => sub {
16             my ($class, $c, $args) = @_;
17             die("Application is not using Catalyst::Plugin::Authentication, $class cannot work.\n") unless $c->can('user');
18             };
19              
20             sub build_per_context_instance {
21 0     0 0   my ($self, $c) = @_;
22 0           my $user = $c->user;
23 0 0         die("No authenticated user") unless $user;
24             # FIXME - This is crap, why do I need to do any of this!
25 0 0         my $i = $user->can('_ldap_connection') ? $user->_ldap_connection->()
26             : $user->ldap_connection;
27 0           my $model = bless $i, 'Catalyst::Model::LDAP::Connection';
28 0   0       $model->{entry_class} ||= 'Catalyst::Model::LDAP::Entry';
29 0   0       $model->{base} ||= 'dc=cissme, dc=com';
30 0           return $model;
31             }
32              
33             __PACKAGE__->meta->make_immutable;
34              
35             =head1 NAME
36              
37             Catalyst::Model::LDAP::FromAuthentication - Provides an LDAP model bound as the user who logged in.
38              
39             =head2 SYNOPSIS
40              
41             package MyApp::Model::LDAP;
42             use Moose;
43             use namespace::autoclean;
44              
45             extends 'Catalyst::Model::LDAP::FromAuthentication';
46              
47             # Elsewhere
48             $c->model('LDAP');
49              
50             =head2 DESCRIPTION
51              
52             This model is a shim used to mash up L<Catalyst::Authentication::Store::LDAP>
53             and L<Catalyst::Model::LDAP>.
54              
55             It will return L<Catalyst::Authentication::Store::LDAP> object bound to the
56             directory as the logged in user.
57              
58             =head1 AUTHOR
59              
60             Tomas Doran (t0m) C<< <bobtfish@bobtfish.net >>
61              
62             =head1 COPYRIGHT
63              
64             Copyright 2009 state51
65              
66             =head1 LICENSE
67              
68             his program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
69              
70             =cut
71