ensembl-hive  2.6
Filter.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4 Copyright [2016-2024] EMBL-European Bioinformatics Institute
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 =cut
19 
20 
21 # =======================================================================
22 # Doxygen Pre-Processor for Perl
23 # Copyright (C) 2002 Bart Schuller
24 # Copyright (C) 2006 Phinex Informatik AG
25 # All Rights Reserved
26 #
27 # Doxygen Filter is free software; you can redistribute it and/or modify
28 # it under the same terms as Perl itself.
29 #
30 # Larry Wall's 'Artistic License' for perl can be found in
31 # http://www.perl.com/pub/a/language/misc/Artistic.html
32 #
33 # =======================================================================
34 #
35 # Author: Aeby Thomas, Phinex Informatik AG,
36 # Based on DoxygenFilter from Bart Schuller
37 # E-Mail: tom.aeby@phinex.ch
38 #
39 # Phinex Informatik AG
40 # Thomas Aeby
41 # Kirchweg 52
42 # 1735 Giffers
43 #
44 # =======================================================================
45 #
46 # @(#) $Id$
47 #
48 # Revision History prior to import into EnsEMBL:
49 #
50 # Revision 1.1 2011-10-18 13:46:34 kt7
51 # Transferring Doxygen filter into EnsEMBL CVS.
52 #
53 # Revision 1.1 2011-05-16 15:31:44 kt7
54 # Preservative backup of all code required to run Doxygen to
55 # generate API reference.
56 #
57 # Revision 1.2 2006/01/31 16:53:52 aeby
58 # added copyright info
59 #
60 #
61 # =======================================================================
62 
63 ## @file
64 # implementation of Filter as derrived from Doxygen::Filter.
65 
66 
67 ## @class
68 # Filter from non-C++ syntax API docs to Doxygen-compatible syntax.
69 # This class is meant to be used as a filter for the
70 # <a href="http://www.doxygen.org/">Doxygen</a> documentation tool.
71 package EnsEMBL::Filter;
72 
73 use warnings;
74 use strict;
75 
76 my $debug_home_location = '';
77 if($ENV{PERL_DOXYGEN_DEBUG_LOCATION}) {
78  $debug_home_location = $ENV{PERL_DOXYGEN_DEBUG_LOCATION};
79 }
80 
81 ## @cmethod object new($outfh)
82 # create a filter object.
83 # @param outfh optional output filehandle; defaults to STDOUT
84 # @return filter object
85 sub new {
86  my $class = shift;
87  my $outfh = shift || \*STDOUT;
88 
89  my $self = bless {outfh => $outfh}, $class;
90 
91  if($debug_home_location) {
92  open(my $debug, '>', $debug_home_location);
93  $self->{debug_fh} = $debug;
94  }
95 
96  return $self;
97 }
98 
99 sub DESTROY {
100  my ($self) = @_;
101  close $self->{debug_fh} if $self->{debug_fh};
102  return;
103 }
104 
105 ## @method virtual void filter($infh)=0
106 # do the filtering.
107 # @param infh input filehandle, normally STDIN
108 sub filter {
109  die "subclass responsibility";
110 }
111 
112 ## @method protected string protection($sig)
113 # Return the protection of a method/function signature.
114 # @param sig the method signature
115 # @return Either "Public" or "Private".
116 sub protection {
117  my($self, $sig) = @_;
118  return $sig =~ /^(private|protected)/ ? "\u$1" : 'Public';
119 }
120 
121 ## @method void start($command)
122 # start a doc comment.
123 # Outputs the start of a javadoc comment.
124 # @param command the javadoc command
125 sub start {
126  my $self = shift;
127  my $command = shift;
128  $self->print("/** $command\n");
129  return $self;
130 }
131 
132 ## @method void end()
133 # end a doc comment.
134 # Outputs the end of a javadoc comment.
135 sub end {
136  my ($self, $tag) = @_;
137  if (defined $tag)
138  {
139  $self->print("$tag */\n");
140  }
141  else
142  {
143  $self->print("*/\n");
144  }
145  return $self;
146 }
147 
148 ## @method void push($section)
149 # Start a diversion to a section.
150 # @param section The name of the section to divert all output to.
151 # @see pop(), print(), flush()
152 sub push {
153  my($self, $section) = @_;
154  $self->{current_section} = $section;
155  return $self;
156 }
157 
158 ## @method void pop()
159 # End a diversion to a section.
160 # @see push(), flush()
161 sub pop {
162  my($self) = @_;
163  delete $self->{current_section};
164  return $self;
165 }
166 
167 ## @method void print(@args)
168 # print a string to the output handle.
169 # If a diversion to a specific section is in effect: saves the text under
170 # that section.
171 # @param args the strings to be printed
172 # @see push(), flush()
173 sub print {
174  my $self = shift;
175  return unless @_;
176  if (my $section = $self->{current_section}) {
177  CORE::push @{$self->{sections}{$section}}, @_;
178  } else {
179  my $outfh = $self->{outfh};
180  print $outfh @_;
181  my $debug_fh = $self->{debug_fh};
182  print $debug_fh @_ if $debug_fh;
183  }
184  return $self;
185 }
186 
187 sub echo {
188  my $self = shift;
189  return unless @_;
190  print STDERR @_;
191  return $self;
192 }
193 
194 ## @method void more(@args)
195 # process the follow-up lines after the initial apidoc line.
196 # @param args the lines to be processed
197 sub more {
198  my $self = shift;
199  $self->print(@_);
200  return $self;
201 }
202 
203 my @order = (
204  'Public Class Methods',
205  'Public Object Methods',
206  'Public Functions',
207  'Protected Class Methods',
208  'Protected Object Methods',
209  'Protected Functions',
210  'Private Class Methods',
211  'Private Object Methods',
212  'Private Functions',
213  );
214 ## @method void flush()
215 # Flush the saved sections. Should be called at the end of a class.
216 # @see push(), print()
217 sub flush {
218  my $self = shift;
219  my $sections = $self->{sections};
220  foreach (@order) {
221  next unless $sections->{$_};
222  $self->start("\@name $_\n")->end;
223  $self->start("\@{")->end;
224  $self->print("\n");
225  $self->print(@{$sections->{$_}});
226  $self->print("\n");
227  $self->start("\@}")->end;
228  $self->print("\n");
229  }
230  delete $self->{sections};
231  return $self;
232 }
233 
234 1;
235 
236 __END__
237 
238 =head1 NAME
239 
240 EnsEMBL::Filter - use DoxyGen with Perl and other languages.
241 
242 =head1 DESCRIPTION
243 
244 Filter from non-C++ syntax API docs to Doxygen-compatible syntax.
245 This class is meant to be used as a filter for the
246 Doxygen (http://www.doxygen.org/) documentation tool
247 
EnsEMBL::Filter
Definition: Filter.pm:2