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   13080 use Bio::Phylo::Util::IDPool;
  57         138  
  57         1553  
3 57     57   9407 use Bio::Phylo::Util::Exceptions 'throw';
  57         133  
  57         2939  
4              
5 57     57   362 use strict;
  57         103  
  57         1023  
6 57     57   258 use warnings;
  57         96  
  57         8531  
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 12044     12044 1 16433 my $class = shift;
46              
47             # happens only and exactly once because this
48             # root class is visited from every constructor
49 12044         29678 my $self = Bio::Phylo::Util::IDPool->_initialize();
50              
51             # bless in child class, not __PACKAGE__
52 12044         21296 bless $self, $class;
53 12044         21530 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 2614590     2614590 1 3216194 my ($self) = @_;
71 2614590 50       4174112 if ( UNIVERSAL::isa( $self, 'SCALAR' ) ) {
72 2614590         6200029 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
102             for any user or developer questions and discussions.
103              
104             Also see the manual: L and L
105              
106             =head1 CITATION
107              
108             If you use Bio::Phylo in published research, please cite it:
109              
110             B, B, B, B
111             and B, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
112             I B<12>:63.
113             L
114              
115             =cut
116              
117             1;