2 # BioPerl module for BaseSAXHandler
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Juguang Xiao, juguang@tll.org.sg
8 # Copyright Juguang Xiao
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::OntologyIO::Handlers::BaseSAXHandler - base class for SAX Handlers
24 This module is an abstract module, serving as the base of any SAX Handler
25 implementation. It tries to offer the framework that SAX handlers generally
26 need, such as tag_stack, char_store, etc.
28 In the implementation handler, you can take advantage of this based module by
29 the following suggestions.
35 my $tag=$_[0]->{Name};
36 my %args=%{$_[0]->{Attributes}};
39 # Before you conclude the method, write these 2 line.
40 $self->_visited_count_inc($tag);
41 $self->_push_tag($tag);
48 my $tag=shift->{Name};
51 # Before you conclude the method, write these 2 lines.
52 $self->_visited_count_dec($tag);
56 3) In characters, or any other methods where you may use the tag
61 my $text=shift->{Data};
63 $self->_chars_hash->{$self->_top_tag} .= $text;
66 $count = $self->_visited_count('myTag');
67 $tag = $self->_top_tag;
74 User feedback is an integral part of the evolution of this and other
75 Bioperl modules. Send your comments and suggestions preferably to one
76 of the Bioperl mailing lists.
78 Your participation is much appreciated.
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
85 Please direct usage questions or support issues to the mailing list:
87 I<bioperl-l@bioperl.org>
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
96 Report bugs to the Bioperl bug tracking system to help us keep track
97 the bugs and their resolution. Bug reports can be submitted via the
100 https://github.com/bioperl/bioperl-live/issues
104 Juguang Xiao, juguang@tll.org.sg
108 The rest of the documentation details each of the object methods.
109 Internal methods are usually preceded with a _
113 package Bio
::OntologyIO
::Handlers
::BaseSAXHandler
;
115 use base
qw(Bio::Root::Root);
119 my ($class, @args) = @_;
120 my $self=$class->SUPER::new
(@args);
121 $self->_initialize(@args);
127 $self->{_tag_stack
} = [];
128 $self->{_visited_count
} = {};
129 $self->{_chars_hash
} = {};
130 $self->{_current_hash
} = {};
136 Usage : @tags = $self->_tag_stack;
137 Function: Get an array of tags that have been accessed but not enclosed.
144 return @
{shift->{_tag_stack
}};
153 push @
{$self->{_tag_stack
}}, $tag;
162 return pop @
{$self->{_tag_stack
}};
168 Usage : $top = $self->_top_tag;
169 Function: get the top tag in the tag stack.
177 my @stack=@
{$self->{_tag_stack
}};
179 # get the last element in an array while remaining it in. There are few ways
182 # 3) $stack[@stack-1]
189 Usage : $hash= $self->_chars_hash;
190 Function: return the character cache for the specific tag
191 Return : a hash reference, which is intent for character storage for tags
197 return shift->{_chars_hash
};
205 return shift->{_current_hash
};
208 =head2 _visited_count_inc
210 Title : _vistied_count_inc
211 Usage : $self->vistied_count_inc($tag); # the counter for the tag increase
212 Function: the counter for the tag increase
213 Return : the current count after this increment
214 Args : the tag name [scalar]
218 sub _visited_count_inc
{
219 my ($self, $tag) = @_;
220 my $visited_count=$self->{_visited_count
};
221 if(exists $visited_count->{$tag}){
222 $visited_count->{$tag}++;
224 $visited_count->{$tag}=1;
226 return $visited_count->{$tag};
229 =head2 _visited_count_dec
231 Title : _visited_count_dec
232 Usage : $self->_visited_count_dec($tag);
233 Function: the counter for the tag decreases by one
234 Return : the current count for the specific tag after the decrement
235 Args : the tag name [scalar]
239 sub _visited_count_dec
{
240 my ($self, $tag) = @_;
241 my $visited_count=$self->{_visited_count
};
242 if(exists $visited_count->{$tag}){
243 $visited_count->{$tag}--;
245 $self->throw("'$tag' has not been visited yet. How to decrease it?!");
247 return $visited_count->{$tag};
250 =head2 _visited_count
252 Title : _visited_count
253 Usage : $count = $self->_visited_count
254 Function: return the counter for the tag
255 Return : the current counter for the specific tag
256 Args : the tag name [scalar]
261 my ($self, $tag) = @_;
262 return $self->{_visited_count
}->{$tag};