NAME
Data::Sah::Compiler::perl - Compile Sah schema to Perl code
VERSION
version 0.18
SYNOPSIS
# see Data::Sah
DESCRIPTION
Derived from Data::Sah::Compiler::Prog.
METHODS
new() => OBJ
Compilation data
This subclass adds the following compilation data ($cd
).
Keys which contain compilation result:
module_statements => HASH
This hash, keyed by module name, lets the Perl compiler differentiate on the different statements to use when loading modules, e.g.:
{ "Foo" => undef, # or does not exist "Bar::Baz" => ['use'], "Qux" => ['use', []], "Quux" => ['use', ["'a'", 123]], "warnings" => ['no'], }
will lead to these codes (in the order specified by
$cd->{modules}
, BTW) being generated:require Foo; use Bar::Baz; use Qux (); use Quux ('a', 123); no warnings;
$c->comment($cd, @args) => STR
Generate a comment. For example, in perl compiler:
$c->comment($cd, "123"); # -> "# 123\n"
Will return an empty string if compile argument comment
is set to false.
$c->compile(%args) => RESULT
Aside from Prog's arguments, this class supports these arguments:
$c->add_use($cd, $module, \@imports)
This is like add_module()
, but indicate that $module
needs to be use
-d in the generated code (for example, Perl pragmas). Normally if add_module()
is used, the generated code will use require
.
If you use $c->add_use($cd, 'foo')
, this code will be generated:
use foo;
If you use $c->add_use($cd, 'foo', ["'a'", "'b'", "123"])
, this code will be generated:
use foo ('a', 'b', 123);
If you use $c->add_use($cd, 'foo', [])
, this code will be generated:
use foo ();
The generated statement will be added at the top (top-level lexical scope) and duplicates are ignored. To generate multiple and lexically-scoped use
and no
statements, e.g. like below, currently you can generate them manually:
if (blah) {
no warnings;
...
}
$c->add_no($cd, $module)
This is the counterpart of add_use()
, to generate <no foo
> statement.
See also: add_use()
.
$c->add_smartmatch_pragma($cd)
Equivalent to:
$c->add_use($cd, 'experimental', ["'smartmatch'"]);
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.