MooseX::Types::Authen::Passphrase - L<Authen::Passphrase> type constraint and


MooseX-Types-Authen-Passphrase documentation Contained in the MooseX-Types-Authen-Passphrase distribution.

Index


Code Index:

NAME

Top

MooseX::Types::Authen::Passphrase - Authen::Passphrase type constraint and coercions

SYNOPSIS

Top

	package User;
	use Moose;

	use MooseX::Types::Authen::Passphrase qw(Passphrase);

	has pass => (
		isa => Passphrase,
		coerce => 1,
		handles => { check_password => "match" },
	);

	User->new( pass => undef ); # Authen::Passphrase::RejectAll

	my $u = User->new( pass => "{SSHA}ixZcpJbwT507Ch1IRB0KjajkjGZUMzX8gA==" );

	$u->check_password("foo"); # great success

	User->new( pass => Authen::Passphrase::Clear->new("foo") ); # clear text is not coerced by default

DESCRIPTION

Top

This MooseX::Types library provides string coercions for the Authen::Passphrase family of classes.

TYPES

Top

Authen::Passphrase

This is defined as a class type

The following coercions are defined

from Undef

Returns Authen::Passphrase::RejectAll

from Str

Parses using from_rfc2307 if the string begins with a {, or using from_crypt otherwise.

VERSION CONTROL

Top

This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.

AUTHOR

Top

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Top


MooseX-Types-Authen-Passphrase documentation Contained in the MooseX-Types-Authen-Passphrase distribution.

#!/usr/bin/perl

package MooseX::Types::Authen::Passphrase;

use strict;
use warnings;

our $VERSION = "0.02";

use Authen::Passphrase;
use Authen::Passphrase::RejectAll;

use MooseX::Types::Moose qw(Str Undef);

use MooseX::Types -declare => [qw(Passphrase)];

use namespace::clean;

class_type "Authen::Passphrase";
class_type Passphrase, { class => "Authen::Passphrase" };

foreach my $type ( "Authen::Passphrase", Passphrase ) {
    coerce( $type,
		from Undef, via { Authen::Passphrase::RejectAll->new },
		from Str, via {
			if ( /^\{/ ) {
				return Authen::Passphrase->from_rfc2307($_);
			} else {
				return Authen::Passphrase->from_crypt($_);
				#my ( $p, $e ) = do { local $@; my $p = eval { Authen::Passphrase->from_crypt($_) }; ( $p, $@ ) };

				#if ( ref $p and $p->isa("Authen::Passphrase::RejectAll") and length($_) ) {
				#	warn "e: $e";
				#	return Authen::Passphrase::Clear->new($_);
				#} elsif ( $e ) {
				#	die $e;
				#} else {
				#	return $p;
				#}
			}		
		},
	);
}

__PACKAGE__

__END__