Icon for Dimension.orgIcon for TalentIcon for ToolsIcon for Doorways.org
Icon for ToolsIcon for Perl Tools

DoxyFilt: Item/Function/Function.pm Source File

  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

Item/Function/Function.pm

Go to the documentation of this file.
00001 package Doxygen::Item::Function;
00002 
00003 =head1 NAME
00004 
00005 Doxygen::Item::Function - Perl extension for generating Doxygen documentation
00006 
00007 =head1 SYNOPSIS
00008 
00009     my  $cls = new Doxygen::Item::Function;
00010 
00011 =head1 ABSTRACT
00012 
00013 A Doxygen::Item::Function object represents C/C++ function/method
00014 from a source file processing by the Doxygen documentation system.
00015 These objects should be created by a specific source-language filter
00016 (subclass of Doxygen::Filter, named Doxygen::I<language>::Filter)
00017 when processing a source file.
00018 
00019 =head1 DESCRIPTION
00020 
00021 =head1 METHODS
00022 
00023 =over
00024 
00025 =cut
00026 
00027 use     5.005;  # just to pick something, but not really tested
00028 use     strict;
00029 use     warnings;
00030 use     UNIVERSAL   qw(isa);
00031 
00032 use     base qw(Doxygen::Item);
00033 
00034 our $VERSION = '0.01';
00035 
00036 my  $stripArg = qr(^\\?[\$\@\%\&]);
00037 
00038 ###########################################################################
00039 ###########################################################################
00040 
00041 =item   C<massage($self, $source)>
00042 
00043 Item-specific massage sequences.
00044 
00045 =cut
00046 
00047 sub massage     # $self, $source
00048 {
00049     my  $self = shift;
00050     
00051 #   print STDERR __PACKAGE__, "::massage($_[0])\n";
00052     
00053     if ($self->argClear('class')) {
00054         $self->{static} = 1;
00055     } elsif ($self->argClear('self') || $self->argClear('this')) {
00056         delete $self->{static}
00057             if exists $self->{static}
00058     }
00059 }
00060 
00061 ###########################################################################
00062 ###########################################################################
00063 
00064 =item   C<generate($self, %flags)>
00065 
00066 Generates output understandable by doxygen to standard output.
00067 
00068 =cut
00069 
00070 sub generate    # $self , %flags
00071 {
00072     my ($self, %flags) = @_;
00073     
00074     $flags{indent} = '' unless defined $flags{indent};
00075     
00076     print "$flags{indent}/**\n";
00077     print "$flags{indent} * \\fn @{[ $self->image ]}\n";
00078     print "$flags{indent} *\n";
00079     $self->genComment(%flags);
00080     
00081     for (@{$self->{arguments}}) {
00082         next
00083             if $_ eq 'self'
00084             || $_ eq 'this'
00085             || $_ eq 'class';
00086         
00087         my  $arg = $self->{argument}->{$_};
00088             
00089         next
00090             unless isa $arg, 'HASH';
00091         
00092         print "$flags{indent} *  \\param $arg->{image} $arg->{comment}\n"
00093             if $arg->{comment};
00094     }
00095     
00096     print "$flags{indent} */\n\n";
00097     
00098     # The function declaration is all one one line:
00099     my  $first = 1;
00100     
00101     print "$flags{indent}static\n" if $self->{static};
00102     print "$flags{indent}", $self->image, ";\n\n";
00103 }
00104 
00105 ###########################################################################
00106 ###########################################################################
00107 
00108 =item   C<argument($self, $arg, $comment)>
00109 
00110 Sets the value of (commented associated with) a single function argument.
00111 
00112 =cut
00113 
00114 sub argument    # $self, $arg, $comment
00115 {
00116     my ($self, $arg, $comment) = @_;
00117     
00118     $self->arguments($arg);    # makes sure arg exists for function
00119     
00120     $arg =~ s/$stripArg//o;
00121     
00122     $self->{argument}->{$arg}->{comment} = $comment
00123         if defined $comment;
00124 }
00125 
00126 ###########################################################################
00127 
00128 =item   C<argClear($self, $arg)>
00129 
00130 Clears named argument so it does not exist anymore.
00131 Returns previous value or argument name if argument existed.
00132 Does not do anything but return undef if argument did not exist.
00133 
00134 =cut
00135 
00136 #=| @param  $arg    Argument name to be cleared (removed)
00137 
00138 sub argClear
00139 {
00140     my ($self, $arg) = @_;
00141     
00142 #   print STDERR __PACKAGE__, "::argClear($arg)\n";
00143     
00144     my  @args = ( );
00145     my  $fnd  = undef;
00146     
00147     $arg =~ s/$stripArg//o;
00148     
00149     for (@{$self->{arguments}}) {
00150         if ($_ eq $arg) {
00151             $fnd = 1;
00152         } else {
00153             push @args, $_;
00154         }
00155     }
00156     
00157     $self->{arguments} = \@args
00158         if $fnd;
00159     
00160     my  $result = $fnd && ($self->{argument}->{$arg}->{comment} || $arg);
00161     
00162     delete $self->{argument}->{$arg}
00163         if exists $self->{argument}->{$arg};
00164         
00165     $result
00166 }
00167 
00168 ###########################################################################
00169 
00170 =item   C<arguments($self, $arguments)>
00171 
00172 Sets arguments for item.
00173 
00174 Just creates basic arguments,
00175 does not add comments but does add option flags
00176 based on initial (removed) C<'?'> in argument name.
00177 
00178 =cut
00179 
00180 sub arguments
00181 {
00182     my ($self, $arguments) = @_;
00183     
00184 #   print STDERR __PACKAGE__, "::arguments($arguments)\n";
00185     
00186     my  $optional = undef;
00187     
00188     for (split(/\s+|[,\[\]]/, $arguments)) {
00189         next unless /\S/s;
00190         next if     /,/;
00191         
00192         if (/[\[\]]/) {
00193             if    (/\[/)        {   $optional++;    }
00194             elsif ($optional)   {   $optional--;    }
00195             next;
00196         }
00197         
00198         # Strip down argument name:
00199         my  $arg = $_;
00200         
00201         $arg =~ s/$stripArg//o;
00202         
00203         my  $fnd = undef;
00204         
00205         for (@{$self->{arguments}}) {
00206             next unless $_ eq $arg;
00207             $fnd = 1;
00208             last;
00209         }
00210         
00211         push @{$self->{arguments}}, $arg
00212             unless $fnd;
00213         
00214         $self->{argument}->{$arg} = { }
00215             unless isa $self->{argument}->{$arg}, 'HASH';
00216             
00217         $self->{argument}->{$arg}->{image} = $_
00218             unless $self->{argument}->{$arg}->{image};
00219         
00220         $self->{argument}->{$arg}->{optional} = 1
00221             if $optional;
00222     }
00223 }
00224 
00225 ###########################################################################
00226 ###########################################################################
00227 
00228 =item   C<image($self, %flags)>
00229 
00230 Return 'image' of the function call.
00231 
00232 =cut
00233 
00234 sub image
00235 {
00236     my ($self, %flags) = @_;
00237     my  $first = 1;
00238     my  $image = ''; # 'void';
00239     
00240     $image .= "\\link $self->{name}() " if $flags{linked};
00241     $image .= "$self->{name}";
00242     $image .= ' \endlink' if $flags{linked};
00243     $image .= ' (';
00244 
00245     for my $arg (@{$self->{arguments}}) {
00246         next
00247             if $arg eq 'self'
00248             || $arg eq 'this'
00249             || $arg eq 'class';
00250         
00251         if ($first) {
00252             undef $first;
00253         } else {
00254             $image .= ', ';
00255         }
00256         
00257         my  $argImg = $self->{argument}->{$arg}->{image} || $arg;
00258         
00259         $argImg =~ s|([%\\\@])|\\$1|g if $flags{escaped};
00260         $image .=  $argImg;
00261     }
00262     
00263     $image .= ')';
00264     $image
00265 }
00266 
00267 ###########################################################################
00268 ###########################################################################
00269 
00270 1
00271 
00272 __END__
00273 
00274 =back
00275 
00276 =head1 SEE ALSO
00277 
00278 DoxyFilt.pl, Doxygen::Item, Doxygen::Filter
00279 
00280 =head1 AUTHOR
00281 
00282 Marc M. Adkins, L<mailto:Perl@Doorways.org>
00283 
00284 =head1 COPYRIGHT AND LICENSE
00285 
00286 Copyright 2004-2010 by Marc M. Adkins
00287 
00288 This library is free software; you can redistribute it and/or modify
00289 it under the same terms as Perl itself.
00290 
00291 =cut

Generated on Mon Dec 27 2010 15:15:39 for DoxyFilt by  doxygen 1.7.1

www.dimension.org logo

(C)opyright 1998 - 2012 Dimension.org

WebMaster