Perl::ToPerl6::Config - The final derived Perl::ToPerl6 configuration, combined from any profile file and command-line parameters.
Perl::ToPerl6::Config takes care of finding and processing user-preferences for Perl::ToPerl6. The Config object defines which Transformer modules will be loaded into the Perl::ToPerl6 engine and how they should be configured. You should never really need to instantiate Perl::ToPerl6::Config directly because the Perl::ToPerl6 constructor will do it for you.
This is considered to be a non-public class. Its interface is subject to change without notice.
new(...)
Not properly documented because you shouldn't be using this.
apply_transform( -transformer => $transformer_name, -params => \%param_hash )
Creates a Transformer object and loads it into this Config. If the object cannot be instantiated, it will throw a fatal exception. Otherwise, it returns a reference to this ToPerl6.
-transformer is the name of a Perl::ToPerl6::Transformer subclass module. The 'Perl::ToPerl6::Transformer' portion of the name can be omitted for brevity. This argument is required.
'Perl::ToPerl6::Transformer'
-params is an optional reference to a hash of Transformer parameters. The contents of this hash reference will be passed into to the constructor of the Transformer module. See the documentation in the relevant Transformer module for a description of the arguments it supports.
all_transformers_enabled_or_not()
Returns a list containing references to all the Transformer objects that have been seen. Note that the state of these objects is not trustworthy. In particular, it is likely that some of them are not prepared to examine any documents.
transformers()
Returns a list containing references to all the Transformer objects that have been enabled and loaded into this Config.
exclude()
Returns the value of the -exclude attribute for this Config.
-exclude
include()
Returns the value of the -include attribute for this Config.
-include
detail()
Returns the value of the -detail attribute for this Config.
-detail
force()
Returns the value of the -force attribute for this Config.
-force
in_place()
Returns the value of the -in-place attribute for this Config.
-in-place
only()
Returns the value of the -only attribute for this Config.
-only
profile_strictness()
Returns the value of the -profile-strictness attribute for this Config.
-profile-strictness
necessity()
Returns the value of the -necessity attribute for this Config.
-necessity
single_transformer()
Returns the value of the -single-transformer attribute for this Config.
-single-transformer
theme()
Returns the Perl::ToPerl6::Theme object that was created for this Config.
top()
Returns the value of the -top attribute for this Config.
-top
verbose()
Returns the value of the -verbose attribute for this Config.
-verbose
color()
Returns the value of the -color attribute for this Config.
-color
pager()
Returns the value of the -pager attribute for this Config.
-pager
color_necessity_highest()
Returns the value of the -color-necessity-highest attribute for this Config.
-color-necessity-highest
color_necessity_high()
Returns the value of the -color-necessity-high attribute for this Config.
-color-necessity-high
color_necessity_medium()
Returns the value of the -color-necessity-medium attribute for this Config.
-color-necessity-medium
color_necessity_low()
Returns the value of the -color-necessity-low attribute for this Config.
-color-necessity-low
color_necessity_lowest()
Returns the value of the -color-necessity-lowest attribute for this Config.
-color-necessity-lowest
program_extensions()
Returns the value of the -program_extensions attribute for this Config. This is an array of the file name extensions that represent program files.
-program_extensions
program_extensions_as_regexes()
Returns the value of the -program_extensions attribute for this Config, as an array of case-sensitive regexes matching the ends of the file names that represent program files.
Perl::ToPerl6::Config has a few static subroutines that are used internally, but may be useful to you in some way.
site_transformer_names()
Returns a list of all the Transformer modules that are currently installed in the Perl::ToPerl6:Transformer namespace. These will include modules that are distributed with Perl::ToPerl6 plus any third-party modules that have been installed.
Most of the settings for Perl::ToPerl6 and each of the Transformer modules can be controlled by a configuration file. The default configuration file is called .perlmogrifyrc. Perl::ToPerl6::Config will look for this file in the current directory first, and then in your home directory. Alternatively, you can set the PERLMOGRIFY environment variable to explicitly point to a different file in another location. If none of these files exist, and the -profile option is not given to the constructor, then all Transformers will be loaded with their default configuration.
PERLMOGRIFY
-profile
The format of the configuration file is a series of INI-style blocks that contain key-value pairs separated by '='. Comments should start with '#' and can be placed on a separate line or after the name-value pairs if you desire.
Default settings for Perl::ToPerl6 itself can be set before the first named block. For example, putting any or all of these at the top of your configuration file will set the default value for the corresponding Perl::ToPerl6 constructor argument.
necessity = 3 #Integer from 1 to 5 in_place = 0 #Zero or One only = 1 #Zero or One detail = 0 #Integer from 1 to 5 force = 0 #Zero or One verbose = 4 #Integer or format spec top = 50 #A positive integer theme = risky + (pbp * security) - cosmetic #A theme expression include = NamingConventions ClassHierarchies #Space-delimited list exclude = Variables Modules::RequirePackage #Space-delimited list color = 1 #Zero or One color-necessity-highest = bold red #Term::ANSIColor color-necessity-high = magenta #Term::ANSIColor color-necessity-medium = #no coloring color-necessity-low = #no coloring color-necessity-lowest = #no coloring program-extensions = #Space-delimited list
The remainder of the configuration file is a series of blocks like this:
[Perl::ToPerl6::Transformer::Category::TransformerName] necessity = 1 set_themes = foo bar add_themes = baz arg1 = value1 arg2 = value2
Perl::ToPerl6::Transformer::Category::TransformerName is the full name of a module that implements the transformer. The Transformer modules distributed with Perl::ToPerl6 have been grouped into categories according to the table of contents in Damian Conway's book Perl Best Practices. For brevity, you can omit the 'Perl::ToPerl6::Transformer' part of the module name.
Perl::ToPerl6::Transformer::Category::TransformerName
necessity is the level of importance you wish to assign to the Transformer. All Transformer modules are defined with a default necessity value ranging from 1 (least severe) to 5 (most severe). However, you may disagree with the default necessity and choose to give it a higher or lower necessity, based on your own coding philosophy.
necessity
The remaining key-value pairs are configuration parameters that will be passed into the constructor of that Transformer. The constructors for most Transformer modules do not support arguments, and those that do should have reasonable defaults. See the documentation on the appropriate Transformer module for more details.
Instead of redefining the necessity for a given Transformer, you can completely disable a Transformer by prepending a '-' to the name of the module in your configuration file. In this manner, the Transformer will never be loaded, regardless of the -necessity given to the Perl::ToPerl6::Config constructor.
A simple configuration might look like this:
#-------------------------------------------------------------- # I think these are really important, so always load them [TestingAndDebugging::RequireUseStrict] necessity = 5 [TestingAndDebugging::RequireUseWarnings] necessity = 5 #-------------------------------------------------------------- # I think these are less important, so only load when asked [Variables::ProhibitPackageVars] necessity = 2 [ControlStructures::ProhibitPostfixControls] allow = if unless #My custom configuration necessity = 2 #-------------------------------------------------------------- # Give these transformers a custom theme. I can activate just # these transformers by saying (-theme => 'larry + curly') [Modules::RequireFilenameMatchesPackage] add_themes = larry [TestingAndDebugging::RequireTestLables] add_themes = curly moe #-------------------------------------------------------------- # I do not agree with these at all, so never load them [-NamingConventions::Capitalization] [-ValuesAndExpressions::ProhibitMagicNumbers] #-------------------------------------------------------------- # For all other Transformers, I accept the default necessity, theme # and other parameters, so no additional configuration is # required for them.
For additional configuration examples, see the perlmogrifyrc file that is included in this t/examples directory of this distribution.
A large number of Transformer modules are distributed with Perl::ToPerl6. They are described briefly in the companion document Perl::ToPerl6::TransformerSummary and in more detail in the individual modules themselves.
Each Transformer is defined with one or more "themes". Themes can be used to create arbitrary groups of Transformers. They are intended to provide an alternative mechanism for selecting your preferred set of Transformers. For example, you may wish disable a certain subset of Transformers when analyzing test programs. Conversely, you may wish to enable only a specific subset of Transformers when analyzing modules.
The Transformers that ship with Perl::ToPerl6 are have been broken into the following themes. This is just our attempt to provide some basic logical groupings. You are free to invent new themes that suit your needs.
THEME DESCRIPTION -------------------------------------------------------------------------- core All transformers that ship with Perl::ToPerl6 pbp Transformers that come directly from "Perl Best Practices" bugs Transformers that prevent or reveal bugs maintenance Transformers that affect the long-term health of the code cosmetic Transformers that only have a superficial effect complexity Transformers that specificaly relate to code complexity security Transformers that relate to security issues tests Transformers that are specific to test programs
Say `perlmogrify -list` to get a listing of all available transformers and the themes that are associated with each one. You can also change the theme for any Transformer in your .perlmogrifyrc file. See the "CONFIGURATION" section for more information about that.
`perlmogrify -list`
Using the -theme option, you can combine theme names with mathematical and boolean operators to create an arbitrarily complex expression that represents a custom "set" of Transformers. The following operators are supported
-theme
Operator Alternative Meaning ---------------------------------------------------------------------------- * and Intersection - not Difference + or Union
Operator precedence is the same as that of normal mathematics. You can also use parenthesis to enforce precedence. Here are some examples:
Expression Meaning ---------------------------------------------------------------------------- pbp * bugs All transformers that are "pbp" AND "bugs" pbp and bugs Ditto bugs + cosmetic All transformers that are "bugs" OR "cosmetic" bugs or cosmetic Ditto pbp - cosmetic All transformers that are "pbp" BUT NOT "cosmetic" pbp not cosmetic Ditto -maintenance All transformers that are NOT "maintenance" not maintenance Ditto (pbp - bugs) * complexity All transformers that are "pbp" BUT NOT "bugs", AND "complexity" (pbp not bugs) and complexity Ditto
Theme names are case-insensitive. If -theme is set to an empty string, then it is equivalent to the set of all Transformers. A theme name that doesn't exist is equivalent to an empty set. Please See http://en.wikipedia.org/wiki/Set for a discussion on set theory.
Perl::ToPerl6::OptionsProcessor, Perl::ToPerl6::UserProfile
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.
To install Perl::ToPerl6, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::ToPerl6
CPAN shell
perl -MCPAN -e shell install Perl::ToPerl6
For more information on module installation, please visit the detailed CPAN module installation guide.