00001 package Doxygen::Filter;
00002
00003 =head1 NAME
00004
00005 Doxygen::Filter - Base class for Doxygen filter classes.
00006
00007 =head1 SYNOPSIS
00008
00009 Inherited by subclass:
00010
00011 use base qw(Doxygen::Filter);
00012
00013 Used in DoxyFilt.pl:
00014
00015 =head1 ABSTRACT
00016
00017 Provides a root class for a source filter for the Doxygen documentation tool.
00018 This class should be inherited by source-specific subclasses, which will in
00019 turn be used by the DoxyFilt.pl script, called by the Doxygen program to
00020 process source files other than C and C++.
00021
00022 =head1 DESCRIPTION
00023
00024 =head1 METHODS
00025
00026 =over
00027
00028 =cut
00029
00030 use 5.005; # just to pick something, but not really tested
00031 use strict;
00032 use warnings;
00033 use UNIVERSAL qw(isa);
00034
00035 use Carp;
00036
00037 use Doxygen::Item::Class;
00038 #se Doxygen::Item::File;
00039
00040 our $VERSION = '0.01';
00041
00042 ###########################################################################
00043 ###########################################################################
00044
00045 =item C<new($class, %flags)>
00046
00047 Constructor for Doxygen::Filter objects.
00048
00049 Collects the flags as a hash and blesses a
00050 reference there, making it easy to set up
00051 initial field values.
00052
00053 =cut
00054
00055 #=| @param %flags Flags used in object creation
00056
00057 sub new
00058 {
00059 my ($class, %flags) = @_;
00060
00061 bless \%flags, $class
00062 }
00063
00064 ###########################################################################
00065 ###########################################################################
00066
00067 =item C<parse($text, $target)>
00068
00069 Parse source text.
00070
00071 Pick out whatever is important for the language or source type.
00072 Collect information on Doxygen::Filter object passed in as the
00073 C<$filter> argument.
00074
00075 Returns true if parsing was successful, otherwise undef or die.
00076
00077 =cut
00078
00079 #=| \param $text text of entire file, passed by value
00080 #=| so it is copied and can be mutilated
00081 #=| as necessary by the filter
00082 #=| \param \$target target object for parsing results,
00083 #=| which are Doxygen::Item instances
00084
00085 sub parse # $self, $text, $target
00086 {
00087 carp ref($_[0]), "::parse not yet implemented\n";
00088
00089 undef
00090 }
00091
00092 ###########################################################################
00093 ###########################################################################
00094
00095 =item C<parseCmnts($self, $text, $source)>
00096
00097 Parse comments from a source file.
00098
00099 Attach results (C<Doxygen::Item> objects) to C<Doxygen::Source> object.
00100
00101 =cut
00102
00103 sub parseCmnts
00104 {
00105 my ($self, $text, $source) = @_;
00106
00107 # $source->log('T', 'parseCmnts(', $text, ', ', $source, ')');
00108
00109 if (my $comment = $self->{cmnt}) {
00110 my $data = ref($text) ? $text : \$text;
00111
00112 return
00113 unless $data
00114 && $$data;
00115
00116 # $source->log('T', $data, '/', $$data);
00117
00118 while ($$data =~ /$comment/g) {
00119 $source->entity->textAppend('notes', "$1\n")
00120 if defined $1;
00121 }
00122 }
00123 }
00124
00125 ###########################################################################
00126 ###########################################################################
00127
00128 =item C<massage($self)>
00129
00130 Massage items in file after parsing and before generating.
00131
00132 Each filter may have a C<massage> method and/or a C<parse> method.
00133 The order of parsing and massaging is undefined except that
00134 I<all> parsing will complete prior to I<any> massaging being done.
00135
00136 This method is the default and therefore does nothing.
00137
00138 =cut
00139
00140 sub massage # $self
00141 {
00142 }
00143
00144 ###########################################################################
00145 ###########################################################################
00146
00147 =item C<coding($self, @text)>
00148
00149 Queue up a line of code to be shown in a box.
00150
00151 Lines of code are collected prior to output.
00152 This method collects then,
00153 the codeFlush() method flushes them as output for doxygen.
00154
00155 =cut
00156
00157 #=| \param @text Lines of code to be queued.
00158
00159 sub coding # $self, @text
00160 {
00161 my $self = shift;
00162
00163 push @{$self->{code}}, @_
00164 }
00165
00166 ###########################################################################
00167
00168 =item C<codeFlush($self)>
00169
00170 Flush all pending code lines.
00171
00172 Code lines are collected via the coding() method.
00173 This method is called to flush the collected lines
00174 in a marked block and clear the collection mechanism.
00175
00176 =cut
00177
00178 sub codeFlush # $self
00179 {
00180 my $self = shift;
00181
00182 return
00183 unless isa($self->{code}, 'ARRAY')
00184 && @{$self->{code}};
00185
00186 $self->focus->comment("\\code");
00187
00188 my @blank = ( );
00189
00190 for (@{$self->{code}}) {
00191 if (/\S/) {
00192 $self->focus->comment(@blank, $_);
00193 @blank = ( );
00194 } else {
00195 push @blank, $_;
00196 }
00197 }
00198
00199 $self->focus->comment("\\endcode");
00200 $self->focus->comment(@blank);
00201
00202 delete $self->{code};
00203 }
00204
00205 ###########################################################################
00206 ###########################################################################
00207
00208 =item C<flags($self)>
00209
00210 Return reference to flags hash for filter.
00211
00212 In general these will be flag default values, and could be
00213 set as a class method.
00214 However, it is easier to code this as an instance method,
00215 and may lend itself to other weirdness later on that account.
00216
00217 The default version returns an empty hash reference.
00218 Filters intending to use this must overload it.
00219
00220 =cut
00221
00222 sub flags
00223 {
00224 { }
00225 }
00226
00227 ###########################################################################
00228 ###########################################################################
00229
00230 =item C<focus($self)>
00231
00232 Return the current focus for adding comment lines.
00233
00234 Defaults to the value for the current source entity,
00235 but may be overridden by descendant classes modelling
00236 language-specific documentation entities.
00237
00238 =cut
00239
00240 #=| \return A Doxygen::Item object.
00241
00242 sub focus # $self
00243 {
00244 $_[0]->entity
00245 }
00246
00247 ###########################################################################
00248 ###########################################################################
00249
00250 =item C<statistics($self, $source)>
00251
00252 Show simple statistics where available.
00253
00254 =cut
00255
00256 sub statistics
00257 {
00258 my ($self, $source) = @_;
00259 my $class = ref $self;
00260 my $found = 0;
00261
00262 $class =~ s|^Doxygen::(.*)::Filter$|$1|;
00263
00264 if (isa($self->{lines}, 'HASH')) {
00265 $source->log('.', join(' ', $class,
00266 map {
00267 "$_($self->{lines}->{$_})"
00268 } sort keys %{$self->{lines}}));
00269 $found = 1;
00270 }
00271
00272 $found
00273 }
00274
00275 ###########################################################################
00276 ###########################################################################
00277
00278 1
00279
00280 __END__
00281
00282 =back
00283
00284 =head1 SEE ALSO
00285
00286 DoxyFilt.pl
00287
00288 =head1 AUTHOR
00289
00290 Marc M. Adkins, F<mailto:Perl@Doorways.org>
00291
00292 =head1 COPYRIGHT AND LICENSE
00293
00294 Copyright 2004-2010 by Marc M. Adkins
00295
00296 This library is free software; you can redistribute it and/or modify
00297 it under the same terms as Perl itself.
00298
00299 =cut