File Coverage

blib/lib/Bio/Phylo/Identifiable.pm
Criterion Covered Total %
statement 19 22 86.3
branch 1 2 50.0
condition n/a
subroutine 6 7 85.7
pod 3 3 100.0
total 29 34 85.2


line stmt bran cond sub pod time code
1             package Bio::Phylo::Identifiable;
2 57     57   13351 use Bio::Phylo::Util::IDPool;
  57         137  
  57         1560  
3 57     57   9713 use Bio::Phylo::Util::Exceptions 'throw';
  57         129  
  57         2846  
4              
5 57     57   326 use strict;
  57         92  
  57         1017  
6 57     57   264 use warnings;
  57         103  
  57         8714  
7              
8             =head1 NAME
9              
10             Bio::Phylo::Identifiable - Objects with unique identifiers
11              
12             =head1 SYNOPSIS
13              
14             # Actually, you would almost never use this module directly. This is
15             # the base class for other modules.
16             use Bio::Phylo::Identifiable;
17            
18             my $obj = Bio::Phylo::Identifiable->new;
19             print $obj->get_id;
20              
21              
22             =head1 DESCRIPTION
23              
24             This is the base class for objects in the Bio::Phylo package
25             that need unique identifiers.
26              
27             =head1 METHODS
28              
29             =head2 CONSTRUCTOR
30              
31             =over
32              
33             =item new()
34              
35             Type : Constructor
36             Title : new
37             Usage : my $phylo = Bio::Phylo::Identifiable->new;
38             Function: Instantiates Bio::Phylo::Identifiable object
39             Returns : a Bio::Phylo::Identifiable object
40             Args : NONE
41              
42             =cut
43              
44             sub new {
45 14624     14624 1 20675 my $class = shift;
46              
47             # happens only and exactly once because this
48             # root class is visited from every constructor
49 14624         37664 my $self = Bio::Phylo::Util::IDPool->_initialize();
50              
51             # bless in child class, not __PACKAGE__
52 14624         25184 bless $self, $class;
53 14624         25209 return $self;
54             }
55              
56             =item get_id()
57              
58             Gets invocant's UID.
59              
60             Type : Accessor
61             Title : get_id
62             Usage : my $id = $obj->get_id;
63             Function: Returns the object's unique ID
64             Returns : INT
65             Args : None
66              
67             =cut
68              
69             sub get_id {
70 2494366     2494366 1 3143048 my ($self) = @_;
71 2494366 50       3952763 if ( UNIVERSAL::isa( $self, 'SCALAR' ) ) {
72 2494366         5868980 return $$self;
73             }
74             else {
75 0           throw 'API' => "Not a SCALAR reference";
76             }
77             }
78              
79             =item is_equal()
80              
81             Compares invocant's UID with argument's UID
82              
83             Type : Test
84             Title : is_equal
85             Usage : do_something() if $obj->is_equal($other);
86             Function: Compares objects by UID
87             Returns : BOOLEAN
88             Args : Another object to compare with
89              
90             =cut
91              
92             sub is_equal {
93 0     0 1   my ($self,$other) = @_;
94 0           return $self->get_id == $other->get_id;
95             }
96              
97             =back
98              
99             =head1 SEE ALSO
100              
101             There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
102             for any user or developer questions and discussions.
103              
104             Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>
105              
106             =head1 CITATION
107              
108             If you use Bio::Phylo in published research, please cite it:
109              
110             B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
111             and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
112             I<BMC Bioinformatics> B<12>:63.
113             L<http://dx.doi.org/10.1186/1471-2105-12-63>
114              
115             =cut
116              
117             1;