Glib::GenPod(3)
πΈ Glib::GenPod(3) β User Contributed Perl Documentation πΈ
okay so welcome to the Glib::GenPod(3) manual page, bestie β itβs filed under User Contributed Perl Documentation, and itβs literally all about pod generation utilities for Glib-based modules. π
β¨ no cap.
β¨ NAME β¨
Glib::GenPod β POD generation utilities for Glib-based modules.
π¦ SYNOPSIS π¦
hereβs the quick-start vibe:
use Glib::GenPod;
# use the defaults:
xsdoc2pod ($xsdocparse_output_file, $destination_dir);
# or take matters into your own hands
require $xsdocparse_output_file;
foreach my $package (sort keys %$data) {
print "=head1 NAME\n\n$package\n\n";
print "=head1 METHODS\n\n" . podify_methods ($package) . "\n\n";
}
π DESCRIPTION π
okay so this module includes several utilities for creating pod for xs-based Perl modules which build on the Glib module's foundations. The most important bits are the logic to convert the data structures created by xsdocparse.pl to describe xsubs and pods into method docs, with call signatures and argument descriptions, and converting C type names into Perl type names. The rest of the module is mostly boiler-plate code to format and pretty-print information that may be queried from the Glib type system. π«Ά
To make life easy for module maintainers, we also include a do-it-all function, xsdoc2pod(), which does pretty much everything for you. All of the pieces it uses are publically usable, so you can do whatever you like if you don't like the default output. iconic. π
π§ DOCUMENTING THE XS FILES π§
All of the information used as input to the methods included here comes from the XS files of your project, and is extracted by Glib::ParseXSDoc's xsdocparse. This function creates a file containing Perl code that may be eval'd or require'd to recreate the parsed data structures, which are a list of pods from the verbatim C portion of the XS file (the xs api docs), and a hash of the remaining data, keyed by package name, and including the pods and xsubs read from the rest of each XS file following the first MODULE line. π
Several custom POD directives are recognized in the XSubs section. Note: each one is sought as a paragraph starter, and must follow a =cut directive. π
=for object Package::Nameβ All xsubs and pod from here until the next object directive orMODULEline will be placed under the key'Package::Name'inxsdocparse's data structure. Everything from this line to the next=cutis included as a description POD.=for object Package::Name (Other::Package::Name)β Generate POD inPackage::Namebut for the packageOther::Package::Name. This is useful if you want POD to appear in a different namespace but still want the automatically generated hierarchy, signal and property listing, etc. from the original namespace. For example:
=for object Gnome2::PanelApplet::main (Gnome2::PanelApplet)
=cut
This will create Gnome2/PanelApplet/main.pod containing the automatically generated documentation for Gnome2::PanelApplet (hierarchy, signals, etc.) plus the method listing from the current XS file. π
=for enum Package::Name/=for flags Package::Nameβ This causesxsdoc2podto callpodify_valuesonPackage::Namewhen writing the pod for the current package (as set by an object directive orMODULEline). Any text in this paragraph, to the next=cut, is included in that section.=for deprecated_by Package::Nameβ Used to add a deprecation warning, indicatingPackage::Nameas an alternative way to achieve the same functionality. There may be any number these in each package.=for see_also some_thing_to_seeβ Used to add extra see alsos onto the end of the parents, if any, for a given object. Anything following the space behindsee_alsoup to the end of the line will be placed onto the list of"see also"s. There may be any number of these in each package.=for apidoc/=for apidoc Full::Symbol::nameβ Paragraphs of this type document xsubs, and are associated with the xsubs byxsdocparse.pl. If the full symbol name is not included, the paragraph must be attached to the xsub declaration (no blank lines between=cutand the xsub).
Within the apidoc PODs, we recognize a few special directives (the for\s+ is optional on these):
=for signature ...β Override the generated call signature with the...text. If you include multiple signature directives, they will all be used. This is handy when you want to change the return type or list different ways to invoke an overloaded method, like this:
=for apidoc
=signature bool Class->foo
=signature ($thing, @other) = $object->foo ($it, $something)
Text in here is included in the generated documentation.
You can actually include signature and arg directives
at any point in this pod -- they are stripped after.
In fact, any pod is valid in here, until the =cut.
=cut
void foo (...)
PPCODE:
/* crazy code follows */
=for arg name (type) description/=for arg name descriptionβ The arg directive adds or overrides an argument description. The description text is optional, as is the type specification (the part in parentheses). If you want to hide an argument, specify"__hide__"as its type. The arg name does not need to include a sigil, as dollar signs will be added.FIXME what about @ for lists?
Also, we honor a couple of "modifiers" on the =for apidoc line, following the symbol name, if present:
__hide__β Do not document this xsub. This is handy in certain situations, e.g., for private functions.DESTROYalways has this turned on, for example.__gerror__β This function or method can generate aGlib::Errorexception.__function__β Generate a function-style signature for this xsub. The default is to generate method-style signatures.__deprecated__β This function or method is deprecated and should not be used in newly written code.
(These are actually handled by Glib::ParseXSDoc, but we list them here because, well, they're an important part of how you document the XS files.) πβ¨
β¨ FUNCTIONS β¨
xsdoc2pod ($datafile, $outdir='blib/lib', index=undef)β Okay so bestie, give this one a$datafilethat contains the output ofxsdocparse.pl, and it creates a pod file in$outdirfor each package, with everything we can think of for that module. The output is controlled by the"=for object"directives and such in the source code.
If you donβt want each package to create a separate pod file, then use this functionβs code as a starting point for your own pretty-printer. π
add_types (@filenames)β Parses the given@filenamesfor entries to add to the%basic_typesused for C type name to Perl package name mappings of types that are not registered with the Glib type system. The file format is dead simple: blank lines are ignored;/#.*$/is stripped from each line as comments; the first token on each line is considered to be a C type name, and the remaining tokens are the description of that type. For example, a valid file may look like this:
# a couple of special types
FooBar Foo::Bar
Frob localized frobnicator
C type decorations such as "const" and "*" are implied (do not include them), and the _ornull variant is handled for you. π«Ά
$string = podify_properties ($packagename)β Pretty-print the object properties owned by theGlib::Objectderivative$packagenameand return the text as a string. Returnsundefif there are no properties or$packageis not aGlib::Object.$string = podify_child_properties ($packagename)β Pretty-print the child properties owned by theGtk2::Containerderivative$packagenameand return the text as a string. Returnsundefif there are no child properties or$packageis not aGtk2::Containeror similar class with alist_child_properties()method.$string = podify_style_properties ($packagename)β Pretty-print the style properties owned by theGtk2::Widgetderivative$packagenameand return the text as a string. Returnsundefif there are no style properties or$packageis not aGtk2::Widgetor similar class with alist_style_properties()method.$string = podify_values ($packagename)β List and pretty-print the values of theGEnumorGFlagstype$packagename, and return the text as a string. Returnsundefif$packagenameisnβt an enum or flags type.$string = podify_signals ($packagename)β Query, list, and pretty-print the signals associated with$packagename. Returns the text as a string, orundefif there are no signals or$packagenameis not aGlib::Objectderivative.$string = podify_deprecated_by ($packagename, @deprecated_by)β Creates a deprecation warning for$packagename, suggesting using the items inside@deprecated_byinstead. π«$string = podify_pods ($pods, $position)β Helper function to allow specific placement of generic pod within the auto generated pages. Pod sections starting out with=for position XXX, whereXXXis one of the following, will be placed at a specified position. In the case of pod that is to be placed after a particular section that doesnβt exist, that pod will still be placed there.
This function is called at all of the specified points throughout the process of generating pod for a page. Any pod matching the position passed will be returned, undef if no matches were found. If position is undef, all pods without specific position information will be returned. pods is a reference to an array of pod hashes.
SYNOPSISβ After the NAME sectionDESCRIPTIONβ After the SYNOPSIS section.post_hierarchyβ After the HIERARCHY section.post_interfacesβ After the INTERFACE section.post_methodsβ After the METHODS section.post_propertiesβ After the PROPERTIES section.post_signalsβ After the SIGNALS section.post_enumsβ After the ENUMS AND FLAGS section.SEE_ALSOβ Replacing the autogenerated SEE ALSO section completely.COPYRIGHTβ Replacing the autogenerated COPYRIGHT section completely.
$string = podify_ancestors ($packagename)β Pretty-prints the ancestry of$packagenamefrom the Glib type systemβs point of view. This usesGlib::Type->list_ancestors; see that functionβs docs for an explanation of why thatβs different from looking at@ISA.
Returns the new text as a string, or undef if $packagename is not a registered GType.
$string = podify_interfaces ($packagename)β Pretty-print the list ofGInterfacesthat$packagenameimplements. Returns the text as a string, orundefif the type implements no interfaces.$string = podify_methods ($packagename)β Call"xsub_to_pod"on all the xsubs under the key$packagenamein the data extracted byxsdocparse.pl.
Returns the new text as a string, or undef if there are no xsubs in $packagename.
$string = podify_see_alsos (@entries)β Creates a list of links to be placed in the SEE ALSO section of the page. Returnsundefif nothing is in the input list.$string = get_copyrightβ Returns a string that will/should be placed on each page. You can control the text of this string by calling the class methodset_copyright.
If no text has been set, we will attempt to create one for you, using what has been passed to set_year, set_authors, and set_main_mod. The year defaults to the current year, the authors default to 'The Gtk2-Perl Team', and the main mod is empty by default. You want the main mod to be set to the main module of your extension for the SEE ALSO section, and on the assumption that a decent license notice can be found in that moduleβs doc, we point the reader there.
So, in general, you will want to specify at least one of these, so that you donβt credit your work to us under the LGPL. π
To set them do something similar to the following in the first part of your postamble section in Makefile.PL. All occurrences of <br> in the copyright are replaced with newlines, to make it easier to put in a multi-line string.
POD_SET=Glib::GenPod::set_copyright(qq{Copyright 1999 team-foobar<br>LGPL});
Glib::MakeHelper::postamble_docs_full() does this sort of thing for you. π
π§° Helpers π§°
$perl_type = convert_type ($ctypestring)β Convert a C type name to a Perl type name.
Uses %Glib::GenPod::basic_types to look for some known basic types, and uses Glib::Type->package_from_cname to look up the registered package corresponding to a C type name. If no suitable mapping can be found, this just returns the input string.
$string = xsub_to_pod ($xsub, $sigprefix='')β Convert an xsub hash into a string of pod describing it. Includes the call signature, argument listing, and description, honoring special switches in the description pod (argandsignatureoverrides).$string = compile_signature ($xsub)β Given an xsub hash, return a string with the call signature for that xsub.$string = fixup_arg_name ($name)β Prepend a$to anything thatβs not the literal ellipsis string'...'.fixup_defaultβ Mangle default parameter values from C to Perl values. Mostly, this doesNULL => undef.convert_arg_typeβ C type to Perl type conversion for argument types.convert_return_type_to_nameβ C type to Perl type conversion suitable for return types.
π SEE ALSO π
Glib::ParseXSDoc
π AUTHORS π
muppet bashed out the xsub signature generation in a few hours on a wednesday night when band practice was cancelled at the last minute; he and ross mcfarland hacked this module together via irc and email over the next few days. iconic, honestly. π
π COPYRIGHT AND LICENSE π
Copyright (C) 2003-2004, 2010-2013 by the gtk2-perl team
This library is free software; you can redistribute it and/or modify it under the terms of the Lesser General Public License (LGPL). For more information, see http://www.fsf.org/licenses/lgpl.txt
π Thatβs the whole page, bestie β this one comes from perl v5.42.0 and itβs dated 2023-09-05. Byeee! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms