prepare for release of C::P::Authentication::Store::Htpasswd
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Plugin / Authentication / Store / Htpasswd / Backend.pm
index 5eecd3d..fa825ca 100644 (file)
@@ -1,38 +1,37 @@
 #!/usr/bin/perl
 
-package Catalyst::Plugin::Authentication::Store::Minimal::Backend;
+package Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
+use base qw/Class::Accessor::Fast/;
 
 use strict;
 use warnings;
 
-use Catalyst::Plugin::Authentication::User::Hash;
-use Scalar::Util ();
+use Authen::Htpasswd;
+use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
+
+BEGIN { __PACKAGE__->mk_accessors(qw/file/) }
 
 sub new {
-    my ( $class, $hash ) = @_;
+    my ( $class, $file, %extra ) = @_;
 
-    bless { hash => $hash }, $class;
+    bless { file => ( ref $file ? $file : Authen::Htpasswd->new($file, \%extra) ) }, $class;
 }
 
 sub get_user {
     my ( $self, $id ) = @_;
-
-       my $user = $self->{hash}{$id};
-
-       bless $user, "Catalyst::Plugin::Authentication::User::Hash"
-         unless Scalar::Util::blessed($user);
-
-    return $user;
+    Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) );
 }
 
 sub user_supports {
     my $self = shift;
 
-    # choose a random user
-    scalar keys %{ $self->{hash} };
-    ( undef, my $user ) = each %{ $self->{hash} };
+    # this can work as a class method
+    Catalyst::Plugin::Authentication::Store::Htpasswd::User->supports(@_);
+}
 
-    $user->supports(@_);
+sub from_session {
+       my ( $self, $c, $id ) = @_;
+       $self->get_user( $id );
 }
 
 __PACKAGE__;
@@ -43,15 +42,15 @@ __END__
 
 =head1 NAME
 
-Catalyst::Plugin::Authentication::Store::Minimal::Backend - Minimal
+Catalyst::Plugin::Authentication::Store::Htpasswd::Backend - Htpasswd
 authentication storage backend.
 
 =head1 SYNOPSIS
 
-    # you probably just want Store::Minimal under most cases,
+    # you probably just want Store::Htpasswd under most cases,
     # but if you insist you can instantiate your own store:
 
-    use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
+    use Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
 
     use Catalyst qw/
         Authentication
@@ -62,7 +61,7 @@ authentication storage backend.
         user => { password => "s3cr3t" },
     );
     
-    our $users = Catalyst::Plugin::Authentication::Store::Minimal::Backend->new(\%users);
+    our $users = Catalyst::Plugin::Authentication::Store::Htpasswd::Backend->new(\%users);
 
     sub action : Local {
         my ( $self, $c ) = @_;
@@ -73,32 +72,34 @@ authentication storage backend.
 
 =head1 DESCRIPTION
 
-You probably want L<Catalyst::Plugin::Authentication::Store::Minimal>, unless
-you are mixing several stores in a single app and one of them is Minimal.
+You probably want L<Catalyst::Plugin::Authentication::Store::Htpasswd>, unless
+you are mixing several stores in a single app and one of them is Htpasswd.
 
 Otherwise, this lets you create a store manually.
 
 =head1 METHODS
 
-=over 4
-
-=item new $hash_ref
+=head2 new $hash_ref
 
 Constructs a new store object, which uses the supplied hash ref as it's backing
 structure.
 
-=item get_user $id
+=head2 get_user $id
 
 Keys the hash by $id and returns the value.
 
 If the return value is unblessed it will be blessed as
 L<Catalyst::Plugin::Authentication::User::Hash>.
 
-=item user_supports
+=head2 user_supports
 
 Chooses a random user from the hash and delegates to it.
 
-=back
+=head1 COPYRIGHT & LICNESE
+
+       Copyright (c) 2005 the aforementioned authors. All rights
+       reserved. This program is free software; you can redistribute
+       it and/or modify it under the same terms as Perl itself.
 
 =cut