# RDoc::Generator - ri - phpman

= [**RDoc::Generator**](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AGenerator/markdown)

(from gem rdoc-7.2.0)
------------------------------------------------------------------------
RDoc uses generators to turn parsed source code in the form of an
[RDoc::CodeObject](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ACodeObject/markdown) tree into some form of output.  RDoc comes with the
HTML generator [RDoc::Generator::Darkfish](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AGenerator%3A%3ADarkfish/markdown) and an ri data generator
[RDoc::Generator::RI](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AGenerator%3A%3ARI/markdown).

== **Registering a Generator**

## Generators are registered by calling [RDoc::RDoc](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ARDoc/markdown).addgenerator with the
class of the generator:

  class [My::Awesome::Generator](https://www.chedong.com/phpMan.php/perldoc/My%3A%3AAwesome%3A%3AGenerator/markdown)
    [RDoc::RDoc](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ARDoc/markdown).add_generator self
  end

== **Adding Options to rdoc**

## Before option processing in rdoc, [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown) will call
::setup_options on the generator class with an [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown) instance.
The generator can use [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown)#option_parser to add command-line
options to the rdoc tool.  See [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown)@Custom+Options for an
example and see OptionParser for details on how to add options.

## You can extend the [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown) instance with additional accessors for
your generator.

== **Generator Instantiation**

## After parsing, [RDoc::RDoc](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ARDoc/markdown) will instantiate a generator by calling
#initialize with an [RDoc::Store](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AStore/markdown) instance and an [RDoc::Options](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AOptions/markdown) instance.

## The [RDoc::Store](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AStore/markdown) instance holds documentation for parsed source code.  In
RDoc 3 and earlier the [RDoc::TopLevel](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ATopLevel/markdown) class held this data.  When
upgrading a generator from RDoc 3 and earlier you should only need to
replace [RDoc::TopLevel](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ATopLevel/markdown) with the store instance.

RDoc will then call #generate on the generator instance.  You can use
the various methods on [RDoc::Store](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3AStore/markdown) and in the [RDoc::CodeObject](https://www.chedong.com/phpMan.php/perldoc/RDoc%3A%3ACodeObject/markdown) tree to
create your desired output format.
------------------------------------------------------------------------
