BASIS  version 1.2.3 (revision 2104)
Filter.pm
Go to the documentation of this file.
00001 
00002 # =======================================================================
00003 # Doxygen Pre-Processor for Perl
00004 # Copyright (C) 2002  Bart Schuller
00005 # Copyright (C) 2006  Phinex Informatik AG
00006 # All Rights Reserved
00007 # 
00008 # Doxygen Filter is free software; you can redistribute it and/or modify
00009 # it under the same terms as Perl itself.
00010 # 
00011 # Larry Wall's 'Artistic License' for perl can be found in
00012 # http://www.perl.com/pub/a/language/misc/Artistic.html
00013 # 
00014 # =======================================================================
00015 # 
00016 # Author: Aeby Thomas, Phinex Informatik AG,
00017 #     Based on DoxygenFilter from Bart Schuller
00018 # E-Mail: tom.aeby@phinex.ch
00019 # 
00020 # Phinex Informatik AG
00021 # Thomas Aeby
00022 # Kirchweg 52
00023 # 1735 Giffers
00024 # 
00025 # =======================================================================
00026 # 
00027 # @(#) $Id: Filter.pm,v 1.2 2006/01/31 16:53:52 aeby Exp $
00028 # 
00029 # Revision History:
00030 # 
00031 # $Log: Filter.pm,v $
00032 # Revision 1.2  2006/01/31 16:53:52  aeby
00033 # added copyright info
00034 #
00035 #  
00036 # =======================================================================
00037 
00038 ## @file Filter.pm
00039 # @brief Implementation of DoxyGen::Filter.
00040 
00041 
00042 ## @class
00043 # Filter from non-C++ syntax API docs to Doxygen-compatible syntax.
00044 # This class is meant to be used as a filter for the
00045 # <a href="http://www.doxygen.org/">Doxygen</a> documentation tool.
00046 package SBIA::BASIS::DoxyGen::Filter;
00047 
00048 use warnings;
00049 use strict;
00050 
00051 ## @method object new($outfh)
00052 # create a filter object.
00053 # @param outfh optional output filehandle; defaults to STDOUT
00054 # @return filter object
00055 sub new {
00056     my $class = shift;
00057     my $outfh = shift || \*STDOUT;
00058     return bless {outfh => $outfh}, $class;
00059 }
00060 
00061 ## @method virtual void filter($infh)=0
00062 # do the filtering.
00063 # @param infh input filehandle, normally STDIN
00064 sub filter {
00065     die "subclass responsibility";
00066 }
00067 
00068 ## @method protected string protection($sig)
00069 # Return the protection of a method/function signature.
00070 # @param sig the method signature
00071 # @return Either "Public" or "Private".
00072 sub protection {
00073     my($self, $sig) = @_;
00074     return $sig =~ /^(private|protected)/ ? "\u$1" : 'Public';
00075 }
00076 
00077 ## @method void start($command)
00078 # start a doc comment.
00079 # Outputs the start of a javadoc comment.
00080 # @param command the javadoc command
00081 sub start {
00082     my $self = shift;
00083     my $command = shift;
00084     $self->print("/** $command\n");
00085     return $self;
00086 }
00087 
00088 ## @method void end()
00089 # end a doc comment.
00090 # Outputs the end of a javadoc comment.
00091 sub end {
00092     my $self = shift;
00093     $self->print("*/\n");
00094     return $self;
00095 }
00096 
00097 ## @method void push($section)
00098 # Start a diversion to a section.
00099 # @param section The name of the section to divert all output to.
00100 # @see pop(), print(), flush()
00101 sub push {
00102     my($self, $section) = @_;
00103     $self->{current_section} = $section;
00104     return $self;
00105 }
00106 
00107 ## @method void pop()
00108 # End a diversion to a section.
00109 # @see push(), flush()
00110 sub pop {
00111     my($self) = @_;
00112     delete $self->{current_section};
00113     return $self;
00114 }
00115 
00116 ## @method void print(@args)
00117 # print a string to the output handle.
00118 # If a diversion to a specific section is in effect: saves the text under
00119 # that section.
00120 # @param args the strings to be printed
00121 # @see push(), flush()
00122 sub print {
00123     my $self = shift;
00124     return unless @_;
00125     if (my $section = $self->{current_section}) {
00126         CORE::push @{$self->{sections}{$section}}, @_;
00127     } else {
00128         my $outfh = $self->{outfh};
00129         print $outfh @_;
00130     }
00131     return $self;
00132 }
00133 
00134 ## @method void more(@args)
00135 # process the follow-up lines after the initial apidoc line.
00136 # @param args the lines to be processed
00137 sub more {
00138     my $self = shift;
00139     $self->print(@_);
00140     return $self;
00141 }
00142 
00143 my @order = (
00144     'Public Class Methods',
00145     'Public Object Methods',
00146     'Public Functions',
00147     'Protected Class Methods',
00148     'Protected Object Methods',
00149     'Protected Functions',
00150     'Private Class Methods',
00151     'Private Object Methods',
00152     'Private Functions',
00153     );
00154 ## @method void flush()
00155 # Flush the saved sections. Should be called at the end of a class.
00156 # @see push(), print()
00157 sub flush {
00158     my $self = shift;
00159     my $sections = $self->{sections};
00160     foreach (@order) {
00161         next unless $sections->{$_};
00162         $self->start("\@name $_\n")->end;
00163         $self->start("\@{")->end;
00164     $self->print("\n");
00165         $self->print(@{$sections->{$_}});
00166     $self->print("\n");
00167         $self->start("\@}")->end;
00168     $self->print("\n");
00169     }
00170     delete $self->{sections};
00171     return $self;
00172 }
00173 
00174 1;
00175 
00176 __END__
00177 
00178 =head1 NAME
00179 
00180 Doxygen::Filter - use DoxyGen with Perl and other languages.
00181 
00182 =head1 DESCRIPTION
00183 
00184 Filter from non-C++ syntax API docs to Doxygen-compatible syntax.
00185 This class is meant to be used as a filter for the
00186 Doxygen (http://www.doxygen.org/) documentation tool
00187