Apache-Wyrd

 view release on metacpan or  search on metacpan

Wyrd/User.pm  view on Meta::CPAN

use 5.006;
use strict;
use warnings;
no warnings qw(uninitialized);

package Apache::Wyrd::User;
our $VERSION = '0.98';
use XML::Dumper;
use Apache::Wyrd::Services::SAK qw(data_clean);
use Digest::SHA qw(sha1_hex);
use Carp;

=pod

=head1 NAME

Apache::Wyrd::User - Abstract user object

=head1 SYNOPSIS

    use BASENAME::User;
    my $user = BASENAME::User->new(
      {
        username => 'fingers',
        password => 'caged whale'
      }
    );
    return AUTHORIZATION_REQUIRED unless (
        $user->auth('elucidated bretheren of the ebon night')
    );

=head1 DESCRIPTION

Provides an object for the storage of user and user-authorization information.

=head1 METHODS

I<(format: (returns) name (arguments after self))>

=over

=item ([anything]) C<foo> ([anything]) (AUTOLOAD)

For most attributes, calling $user->foo where foo is the name of the attribute
will return the value.  If an argument is supplied, the value is set to the
value of the argument.  Exceptions are below.

=cut

sub AUTOLOAD {
	no strict 'vars';
	my ($self, $newval) = @_;
	return undef if $AUTOLOAD =~ /DESTROY$/;
	$AUTOLOAD =~ s/.*:://;
	confess "$AUTOLOAD was called as a method, not a sub " unless (ref($self));
	if(defined($self->{$AUTOLOAD})){
		return $self->{$AUTOLOAD} unless (scalar(@_) == 2);
		$self->{$AUTOLOAD} = $newval;
		return $newval;
	} else {
		$self->{$AUTOLOAD} = $newval;
		return;
	}
}

=pod

=item (Apache::Wyrd::User) C<new> (hashref)

Create a new User object, with, at minimum, B<username>, B<password>, B<auth>,
and B<auth_error> attributes.

=cut

sub new {
	my ($class, $init) = @_;
	if (ref($init) ne 'HASH') {
		#probably not logged in.  Use a blank.
		$init = {};
	}
	$init->{'username'} ||= '';
	$init->{'password'} ||= '';
	$init->{'auth'} ||= {};
	$init->{'auth_error'} ||= '';
	bless $init, $class;
	my $credential_name = $init->name_credentials;
	$init->{$credential_name} = $init->make_credentials;
	$init->get_authorization;
	return $init;



( run in 1.340 second using v1.01-cache-2.11-cpan-39bf76dae61 )