use
5.006001;
sub
new {
my
(
$class
,
%args
) =
@_
;
my
$self
=
bless
{},
$class
;
my
$transformers
=
$args
{-transformers} || [];
$self
->{_transformers} = [
sort
_by_type @{
$transformers
} ];
my
$comment_out_parameters
=
$args
{
'-comment-out-parameters'
};
if
(not
defined
$comment_out_parameters
) {
$comment_out_parameters
= 1;
}
$self
->{_comment_out_parameters} =
$comment_out_parameters
;
my
$configuration
=
$args
{
'-config'
};
if
(not
$configuration
) {
$configuration
= Perl::ToPerl6::Config->new(
-profile
=>
$EMPTY
);
}
$self
->{_configuration} =
$configuration
;
return
$self
;
}
sub
_get_transformers {
my
(
$self
) =
@_
;
return
$self
->{_transformers};
}
sub
_comment_out_parameters {
my
(
$self
) =
@_
;
return
$self
->{_comment_out_parameters};
}
sub
_configuration {
my
(
$self
) =
@_
;
return
$self
->{_configuration};
}
sub
_line_prefix {
my
(
$self
) =
@_
;
return
$self
->_comment_out_parameters() ?
q{# }
:
$EMPTY
;
}
sub
to_string {
my
(
$self
) =
@_
;
my
$prefix
=
$self
->_line_prefix();
my
$configuration
=
$self
->_configuration();
my
$prototype
=
"# Globals\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{necessity = }
;
$prototype
.=
$configuration
->necessity();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{detail = }
;
$prototype
.=
$configuration
->detail();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{force = }
;
$prototype
.=
$configuration
->force();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{in-place = }
;
$prototype
.=
$configuration
->in_place();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{only = }
;
$prototype
.=
$configuration
->only();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{profile-strictness = }
;
$prototype
.=
$configuration
->profile_strictness();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{color = }
;
$prototype
.=
$configuration
->color();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{pager = }
;
$prototype
.=
$configuration
->pager();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{top = }
;
$prototype
.=
$configuration
->top();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{verbose = }
;
$prototype
.=
$configuration
->verbose();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{include = }
;
$prototype
.=
join
$SPACE
,
$configuration
->include();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{exclude = }
;
$prototype
.=
join
$SPACE
,
$configuration
->exclude();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{single-transformer = }
;
$prototype
.=
join
$SPACE
,
$configuration
->single_transformer();
$prototype
.=
"\n"
;
$prototype
.=
$prefix
;
$prototype
.=
q{theme = }
;
$prototype
.=
$configuration
->theme()->rule();
$prototype
.=
"\n"
;
foreach
my
$item
(
qw<
color-necessity-highest
color-necessity-high
color-necessity-medium
color-necessity-low
color-necessity-lowest
>
) {
(
my
$accessor
=
$item
) =~ s/ - /_/gmsx;
$prototype
.=
$prefix
;
$prototype
.=
"$item = "
;
$prototype
.=
$configuration
->
$accessor
;
$prototype
.=
"\n"
;
}
$prototype
.=
$prefix
;
$prototype
.=
q{program-extensions = }
;
$prototype
.=
join
$SPACE
,
$configuration
->program_extensions();
Perl::ToPerl6::Transformer::set_format(
$self
->_proto_format() );
my
$transformer_prototypes
=
join
qq{\n}
,
map
{
"$_"
} @{
$self
->_get_transformers() };
$transformer_prototypes
=~ s/\s+ \z//xms;
return
$prototype
.
"\n\n"
.
$transformer_prototypes
.
"\n"
;
}
sub
_proto_format {
my
(
$self
) =
@_
;
my
$prefix
=
$self
->_line_prefix();
return
<<"END_OF_FORMAT";
# %a
[%p]
${prefix}set_themes = %t
${prefix}add_themes =
${prefix}necessity = %s
%{\\n%\\x7b# \\x7df\\n${prefix}%n = %D\\n}O%{${prefix}Cannot programmatically discover what parameters this transformer takes.\\n}U
END_OF_FORMAT
}
sub
_by_type {
return
ref
$a
cmp
ref
$b
}
1;