package Bio::Phylo::Identifiable;
use Bio::Phylo::Util::IDPool;
use Bio::Phylo::Util::Exceptions 'throw';

use strict;
use warnings;

=head1 NAME

Bio::Phylo::Identifiable - Objects with unique identifiers


 # Actually, you would almost never use this module directly. This is 
 # the base class for other modules.
 use Bio::Phylo::Identifiable;
 my $obj = Bio::Phylo::Identifiable->new;
 print $obj->get_id;


This is the base class for objects in the Bio::Phylo package 
that need unique identifiers.

=head1 METHODS



=item new()

 Type    : Constructor
 Title   : new
 Usage   : my $phylo = Bio::Phylo::Identifiable->new;
 Function: Instantiates Bio::Phylo::Identifiable object
 Returns : a Bio::Phylo::Identifiable object 
 Args    : NONE


sub new {
    my $class = shift;

    # happens only and exactly once because this
    # root class is visited from every constructor
    my $self = Bio::Phylo::Util::IDPool->_initialize();

    # bless in child class, not __PACKAGE__
    bless $self, $class;
    return $self;

=item get_id()

Gets invocant's UID.

 Type    : Accessor
 Title   : get_id
 Usage   : my $id = $obj->get_id;
 Function: Returns the object's unique ID
 Returns : INT
 Args    : None


sub get_id {
    my ($self) = @_;
    if ( UNIVERSAL::isa( $self, 'SCALAR' ) ) {
        return $$self;
    else {
        throw 'API' => "Not a SCALAR reference";

=item is_equal()

Compares invocant's UID with argument's UID

 Type    : Test
 Title   : is_equal
 Usage   : do_something() if $obj->is_equal($other);
 Function: Compares objects by UID
 Returns : BOOLEAN
 Args    : Another object to compare with


sub is_equal {
	my ($self,$other) = @_;
	return $self->get_id == $other->get_id;


=head1 SEE ALSO

There is a mailing list at L<!forum/bio-phylo> 
for any user or developer questions and discussions.

Also see the manual: L<Bio::Phylo::Manual> and L<>


If you use Bio::Phylo in published research, please cite it:

B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
I<BMC Bioinformatics> B<12>:63.