PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Autodia.pm

http://autodia.googlecode.com/
Perl | 251 lines | 166 code | 81 blank | 4 comment | 7 complexity | 2c82af2834e51f9c44096931a094039f MD5 | raw file
Possible License(s): GPL-2.0
  1. package Autodia;
  2. use strict;
  3. =head1 NAME
  4. Autodia.pm - The configuration and Utility perl module for AutoDia.
  5. =head1 VERSION
  6. 2.14
  7. =head1 DESCRIPTION
  8. AutoDia takes source files as input and using a handler parses them to create documentation through templates. The handlers allow AutoDia to parse any language by providing
  9. a handler and registering in in autodia.pm. The templates allow the output to be heavily customised from Dia XML to simple HTML and seperates the logic of the application
  10. from the presentation of the results.
  11. AutoDia is written in perl and defaults to the perl handler and file extension matching unless a language is specified using the -l switch.
  12. AutoDia requires Template Toolkit and Perl 5. Some handlers and templates may require additional software.
  13. Helpful information, links and news can be found at the autodia website - http://www.aarontrevena.co.uk/opensource/autodia/
  14. =head1 METHODS
  15. =over 4
  16. =item getHandlers
  17. =item getPattern
  18. =item setConfig
  19. =back
  20. =head1 Configuring AutoDia via Autodia.pm
  21. To add handlers or languages edit this file.
  22. =over 4
  23. =item To add a handler/parser
  24. Add the language or name of the parser and the name of the module to the %handlers hash in the getHandlers function.
  25. for example :
  26. "perl" => 'HandlerPerl',
  27. Documentation on writing your own handler can be found in the HandlerPerl and Handler perl modules
  28. =item To add a new language or file extension or file matching patter
  29. Add the name of the pattern and a hashreference to its properties to %patterns in the get_patterns function.
  30. for example :
  31. "perl" => \%perl,
  32. Create a hash of its properties that will be pointed to by the above hashref
  33. for example :
  34. my %perl = (
  35. regex => '\w+\.p[ml]$',
  36. wildcards => [
  37. "pl", "pm",
  38. ],
  39. );
  40. =back
  41. =cut
  42. ###############################################################
  43. BEGIN {
  44. use Exporter ();
  45. use vars qw($VERSION @ISA @EXPORT);
  46. $VERSION = "2.14";
  47. @ISA = qw(Exporter);
  48. @EXPORT = qw(
  49. &getHandlers
  50. &getPattern
  51. );
  52. }
  53. #---------------
  54. my %config;
  55. ###############################################################
  56. sub setConfig
  57. { %config = %{$_[1]}; }
  58. sub getHandlers
  59. {
  60. my %handlers = (
  61. "perl" => 'Autodia::Handler::Perl',
  62. 'c++' => 'Autodia::Handler::Cpp',
  63. "csharp" => 'Autodia::Handler::CSharp',
  64. "cpp" => 'Autodia::Handler::Cpp',
  65. "php" => 'Autodia::Handler::PHP',
  66. "dbi" => 'Autodia::Handler::DBI',
  67. "dbi_sqlt" => 'Autodia::Handler::DBI_SQLT',
  68. "dia" => 'Autodia::Handler::dia',
  69. "sql" => 'Autodia::Handler::SQL',
  70. "torque" => 'Autodia::Handler::Torque',
  71. "python" => 'Autodia::Handler::python',
  72. "umbrello" => 'Autodia::Handler::umbrello',
  73. "asp" => 'Autodia::Handler::ASP',
  74. "mason" => 'Autodia::Handler::Mason',
  75. );
  76. print "getting handlers..\n" unless ( $config{silent} );
  77. return \%handlers;
  78. }
  79. sub getPattern
  80. {
  81. my $language = lc($config{language});
  82. print "getting pattern for $language\n" unless ( $config{silent} );
  83. my %perl = (
  84. regex => '\w+\.(?:p[ml]|cgi)$',
  85. wildcards => [
  86. "pl", "pm", "cgi",
  87. ],
  88. );
  89. my %php = (
  90. regex => '\w+\.php(?:3|4)?$',
  91. wildcards => [
  92. "php", "php3", "php4",
  93. ],
  94. );
  95. my %cpp = (
  96. regex => '\w+\.(c|cpp|hh?)$',
  97. wildcards => [
  98. "c", "cpp", "h","hh"
  99. ],
  100. );
  101. my %csharp = (
  102. regex => '\w+\.(cs)$',
  103. wildcards => [
  104. "cs"
  105. ],
  106. );
  107. my %python = (
  108. regex => '\w+.py$',
  109. wildcards => [ 'py', ]
  110. );
  111. my %dia = ( regex => '\w+.dia',
  112. wildcards => ['dia'],
  113. );
  114. my %sql = ( regex => '\w+.sql',
  115. wildcards => ['sql'],
  116. );
  117. my %umbrello = ( regex => '\w+.xmi',
  118. wildcards => ['xmi'],
  119. );
  120. my %asp = ( regex => '\w+.asp',
  121. wildcards => ['asp'],
  122. );
  123. my %mason = ( regex => '\w+(.(mas|m?html)|handler)$',
  124. wildcards => ['mas', 'html', 'mhtml'],
  125. );
  126. my %patterns = (
  127. "perl" => \%perl,
  128. 'c++' => \%cpp,
  129. "cpp" => \%cpp,
  130. "csharp" => \%csharp,
  131. "php" => \%php,
  132. "dbi" => {},
  133. "dia" => \%dia,
  134. "sql" => \%sql,
  135. "torque" => {},
  136. "python" => \%python,
  137. "umbrello" => \%umbrello,
  138. "asp" => \%asp,
  139. "mason" => \%mason,
  140. );
  141. return \%{$patterns{$language}};
  142. }
  143. ###############################################################
  144. =head1 USAGE
  145. use the autodia.pl script to run autodia.
  146. =over 4
  147. =item autodia.pl ([-i filename [-p path] ] or [-d directory [-r] ]) [options]
  148. =item autodia.pl -i filename : use filename as input
  149. =item autodia.pl -i 'filea fileb filec' : use filea, fileb and filec as input
  150. =item autodia.pl -i filename -p .. : use ../filename as input file
  151. =item autodia.pl -d directoryname : use *.pl/pm in directoryname as input files
  152. =item autodia.pl -d 'foo bar quz' : use *pl/pm in directories foo, bar and quz as input files
  153. =item autodia.pl -d directory -r : use *pl/pm in directory and its subdirectories as input files
  154. =item autodia.pl -o outfile.xml : use outfile.xml as output file (otherwise uses autodial.out.xml)
  155. =item autodia.pl -m [file|directory] : use multiple output files split by file or directory (creates an autodia-files directory containing files)
  156. =item autodia.pl -O : output to stdout
  157. =item autodia.pl -l language : parse source as language (ie: C) and look for appropriate filename extensions if also -d
  158. =item autodia.pl -t templatefile : use templatefile as template (otherwise uses template.xml)
  159. =item autodia.pl -S : silent mode, no output to stdout except with -O
  160. =item autodia.pl -h : display this help message
  161. =back
  162. =head1 AUTHOR
  163. Aaron Trevena, E<lt>aaron.trevena@gmail.comE<gt>
  164. =head1 COPYRIGHT AND LICENSE
  165. Copyright (C) 2001 - 2007 by Aaron Trevena
  166. This library is free software; you can redistribute it and/or modify
  167. it under the same terms as Perl itself, either Perl version 5.8.1 or,
  168. at your option, any later version of Perl 5 you may have available.
  169. =cut
  170. 1;