Business::FR::SSN - Verify French SSN (Social Security Number / Numéro de Sécurité Sociale)


Business-FR-SSN documentation Contained in the Business-FR-SSN distribution.

Index


Code Index:

NAME

Top

Business::FR::SSN - Verify French SSN (Social Security Number / Numéro de Sécurité Sociale)

SYNOPSIS

Top

  use Business::FR::SSN;

DESCRIPTION

Top

This module verifies SSN (numéro de sécurité sociale), which are french people identification. This module cannot tell if a SS references a real person, but it can tell you if the given SS is properly formatted.

METHODS

Top

my $obj = Business::FR::SSN->new([$ssn])

The new constructor optionally takes a ss number.

$obj->ssn([$ssn])

if no argument is given, it returns the current ssn number. if an argument is provided, it will set the ssn number and return it.

$obj->is_valid([$ssn])

Returns true if the ssn number is valid.

$obj->get_sex()

Returns 1 for a male, 2 for a female.

$obj->get_birth_year()

Returns the person year of birth.

$obj->get_birth_month()

Returns the person month of birth.

$obj->get_birth_department()

Returns the person department of birth.

REQUESTS & BUGS

Top

Please report any requests, suggestions or bugs via the RT bug-tracking system at http://rt.cpan.org/ or email to bug-Business-FR-SSN\@rt.cpan.org.

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-FR-SSN is the RT queue for Business::FR::SSN. Please check to see if your bug has already been reported.

COPYRIGHT

Top

SEE ALSO

Top

perl(1).


Business-FR-SSN documentation Contained in the Business-FR-SSN distribution.

package Business::FR::SSN;

use strict;
use warnings;

our $VERSION = '1.00';

sub _check_ssn {
	my ($class, $ssn) = @_;

	$ssn =~ s#\s+##g;

	# SSN are 15 \d
	return '' if ($ssn !~ /^\d{15}$/);

	# SSN begins with 1 or 2
	return '' if ($ssn !~ /^(1|2)/);

	# SSN contains birth month (1 > 12)
	my $birth = substr($ssn, 3, 2);
	return '' if (($birth > 12) or ($birth == 0));

	return $ssn;
}

sub new {
	my ($class, $ssn) = @_;

	my $self = bless \$ssn, $class;

	$ssn ||= '';
	$ssn = $self->_check_ssn($ssn);

	$self;
}

sub is_valid {
	my $self = shift;
	my $ssn = shift;

	$$self = $self->_check_ssn($ssn) if ($ssn);

	(substr($$self, 13, 2) == (97 - (substr($$self, 0, 13) % 97))) ? return 1 : return 0;
}

sub ssn {
	my $self = shift;
	my $ssn = shift;

	$$self = $self->_check_ssn($ssn) if ($ssn);

	return $$self;
}

sub get_sex {
	my $self = shift;

	return substr($$self, 0, 1);
}

sub get_birth_year {
	my $self = shift;

	return substr($$self, 1, 2);
}

sub get_birth_month {
	my $self = shift;

	return substr($$self, 3, 2);
}

sub get_birth_department {
	my $self = shift;

	return substr($$self, 5, 2);
}

1;

__END__