Permalink
Browse files

detab

  • Loading branch information...
1 parent fe3eac6 commit d93a8b26b35a26267cd1d4b087fd2df2922346e5 @nothingmuch committed Jul 9, 2010
Showing with 92 additions and 83 deletions.
  1. +14 −13 Makefile.PL
  2. +32 −29 lib/KiokuX/User.pm
  3. +11 −10 lib/KiokuX/User/ID.pm
  4. +5 −4 lib/KiokuX/User/Password.pm
  5. +23 −22 lib/KiokuX/User/Util.pm
  6. +7 −5 t/basic.t
View
@@ -5,18 +5,19 @@ use strict;
use ExtUtils::MakeMaker;
WriteMakefile(
- NAME => 'KiokuX::User',
- VERSION_FROM => 'lib/KiokuX/User.pm',
- INSTALLDIRS => 'site',
- SIGN => 1,
- PL_FILES => { },
- PREREQ_PM => {
- 'Test::use::ok' => 0,
- 'namespace::clean' => 0,
- 'Moose' => 0.63,
- 'KiokuDB' => 0.09,
- 'Sub::Exporter' => 0,
- 'MooseX::Types::Authen::Passphrase' => 0,
- },
+ NAME => 'KiokuX::User',
+ VERSION_FROM => 'lib/KiokuX/User.pm',
+ INSTALLDIRS => 'site',
+ SIGN => 1,
+ PL_FILES => { },
+ PREREQ_PM => {
+ 'Test::use::ok' => 0,
+ 'namespace::clean' => 0,
+ 'Moose' => 0.63,
+ 'KiokuDB' => 0.09,
+ 'Sub::Exporter' => 0,
+ 'MooseX::Types::Authen::Passphrase' => 0,
+ },
);
+# ex: set sw=4 et:
View
@@ -8,8 +8,8 @@ use namespace::clean -except => 'meta';
our $VERSION = "0.01";
with qw(
- KiokuX::User::ID
- KiokuX::User::Password
+ KiokuX::User::ID
+ KiokuX::User::Password
);
__PACKAGE__
@@ -24,25 +24,25 @@ KiokuX::User - A generic role for user objects stored in L<KiokuDB>
=head1 SYNOPSIS
- package MyFoo::Schema::User;
- use Moose;
+ package MyFoo::Schema::User;
+ use Moose;
- use KiokuX::User::Util qw(crypt_password);
+ use KiokuX::User::Util qw(crypt_password);
- with qw(KiokuX::User);
+ with qw(KiokuX::User);
- my $user = MyFoo::Schema::User->new(
- id => $user_id,
- password => crypt_password($password),
- );
+ my $user = MyFoo::Schema::User->new(
+ id => $user_id,
+ password => crypt_password($password),
+ );
- $user->kiokudb_object_id; # "user:$user_id"
+ $user->kiokudb_object_id; # "user:$user_id"
- if ( $user->check_password($read_password) ) {
- warn "Login successful";
- } else {
- warn "Login failed";
- }
+ if ( $user->check_password($read_password) ) {
+ warn "Login successful";
+ } else {
+ warn "Login failed";
+ }
=head1 DESCRIPTION
@@ -63,24 +63,24 @@ If you want to support renaming, multiple authentication methods (e.g. a
password and/or an openid), it's best to create identity delegates that consume
this role, and have them point at the actual user object:
- package MyFoo::Schema::Identity;
- use Moose::Role;
+ package MyFoo::Schema::Identity;
+ use Moose::Role;
- has user => (
- isa => "MyFoo::Schema::User",
- is => "ro",
- required => 1,
- );
+ has user => (
+ isa => "MyFoo::Schema::User",
+ is => "ro",
+ required => 1,
+ );
And here's an example username identity:
- package MyFoo::Schema::Identity::Username;
- use Moose;
+ package MyFoo::Schema::Identity::Username;
+ use Moose;
- with qw(
- MyFoo::Schema::Identity
- KiokuX::User
- );
+ with qw(
+ MyFoo::Schema::Identity
+ KiokuX::User
+ );
and then point back to these identities from the user:
@@ -114,3 +114,6 @@ Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
it and/or modify it under the same terms as Perl itself.
=cut
+
+# ex: set sw=4 et:
+
View
@@ -8,13 +8,13 @@ use namespace::clean -except => 'meta';
with qw(KiokuDB::Role::ID);
sub id_for_user {
- my ( $self, $id ) = @_;
- return "user:$id"
+ my ( $self, $id ) = @_;
+ return "user:$id"
}
sub kiokudb_object_id {
- my $self = shift;
- $self->id_for_user($self->id);
+ my $self = shift;
+ $self->id_for_user($self->id);
}
has id => (
@@ -35,7 +35,7 @@ KiokuX::User::ID - L<KiokuDB::Role::ID> integration for user objects
=head1 SYNOPSIS
- with qw(KiokuX::User::ID);
+ with qw(KiokuX::User::ID);
=head1 DESCRIPTION
@@ -61,13 +61,13 @@ Can be overriden to provide custom namespacing.
Can also be used as a class method from the model:
- sub get_identity_by_username {
- my ( $self, $username ) = @_;
+ sub get_identity_by_username {
+ my ( $self, $username ) = @_;
- my $object_id = MyFoo::Schema::Identity::Username->id_for_user($username);
+ my $object_id = MyFoo::Schema::Identity::Username->id_for_user($username);
- return $self->lookup($object_id);
- }
+ return $self->lookup($object_id);
+ }
=back
@@ -84,4 +84,5 @@ is derived from it.
=cut
+# ex: set sw=4 et:
@@ -13,7 +13,7 @@ has password => (
isa => Passphrase,
is => 'rw',
coerce => 1,
- required => 1,
+ required => 1,
#handles => { check_password => "match" },
);
@@ -23,8 +23,8 @@ sub check_password {
}
sub set_password {
- my ( $self, @args ) = @_;
- $self->password( crypt_password(@args) );
+ my ( $self, @args ) = @_;
+ $self->password( crypt_password(@args) );
}
__PACKAGE__
@@ -39,7 +39,7 @@ KiokuX::User::Password - A role for users with a password attribute
=head1 SYNOPSIS
- with qw(KiokuX::User::Password);
+ with qw(KiokuX::User::Password);
=head1 DESCRIPTION
@@ -69,4 +69,5 @@ This is a required, read-write attribute.
=cut
+# ex: set sw=4 et:
View
@@ -6,35 +6,35 @@ use strict;
use warnings;
use Sub::Exporter -setup => {
- exports => [qw(
- crypt_password
- )],
+ exports => [qw(
+ crypt_password
+ )],
};
use Class::MOP;
sub crypt_password {
- my @args = @_;
+ my @args = @_;
- unshift @args, "passphrase" if @args % 2 == 1;
+ unshift @args, "passphrase" if @args % 2 == 1;
- my %args = @args;
+ my %args = @args;
- unless ( exists $args{class} ) {
- %args = (
- class => "Authen::Passphrase::SaltedDigest",
- salt_random => 20,
- algorithm => "SHA-1",
- %args,
- );
- }
+ unless ( exists $args{class} ) {
+ %args = (
+ class => "Authen::Passphrase::SaltedDigest",
+ salt_random => 20,
+ algorithm => "SHA-1",
+ %args,
+ );
+ }
- my $class = delete $args{class};
+ my $class = delete $args{class};
- Class::MOP::load_class($class);
+ Class::MOP::load_class($class);
- $class->new(%args);
+ $class->new(%args);
}
__PACKAGE__
@@ -49,12 +49,12 @@ KiokuX::User::Util - Utility functions for L<KiokuX::User>
=head1 SYNOPSIS
- use KiokuX::User::Util;
+ use KiokuX::User::Util;
- MyFoo::User->new(
- id => "cutegirl17",
- password => crypt_password("justin timberlake!!!"),
- );
+ MyFoo::User->new(
+ id => "cutegirl17",
+ password => crypt_password("justin timberlake!!!"),
+ );
=head1 DESCRIPTION
@@ -75,4 +75,5 @@ random salt.
=cut
+# ex: set sw=4 et:
View
@@ -10,15 +10,15 @@ use ok 'KiokuX::User';
use ok 'KiokuX::User::Util' => qw(crypt_password);
{
- package Foo::User;
- use Moose;
+ package Foo::User;
+ use Moose;
- with qw(KiokuX::User);
+ with qw(KiokuX::User);
}
my $o = Foo::User->new(
- id => "bar",
- password => crypt_password("foo"),
+ id => "bar",
+ password => crypt_password("foo"),
);
does_ok( $o, "KiokuX::User" );
@@ -45,3 +45,5 @@ ok !$o->check_password("foo"), "password changed";
ok $o->check_password("bar"), "new password";
+# ex: set sw=4 et:
+

0 comments on commit d93a8b2

Please sign in to comment.