![]() |
![]()
| ![]() |
![]()
NAMEData::Sah::Compiler::perl - Compile Sah schema to Perl code VERSIONThis document describes version 0.917 of Data::Sah::Compiler::perl (from Perl distribution Data-Sah), released on 2024-02-16. SYNOPSIS# see Data::Sah DESCRIPTIONDerived from Data::Sah::Compiler::Prog. VARIABLES$PP => boolSet default for "pp" compile argument. Takes precedence over environment "DATA_SAH_PP". $CORE => boolSet default for "core" compile argument. Takes precedence over environment "DATA_SAH_CORE". $CORE_OR_PP => boolSet default for "core_or_pp" compile argument. Takes precedence over environment "DATA_SAH_CORE_OR_PP". $NO_MODULES => boolSet default for "no_modules" compile argument. Takes precedence over environment "DATA_SAH_NO_MODULES". DEVELOPER NOTESTo generate expression code that says "all subexpression must be true", you can do: !defined(List::Util::first(sub { blah($_) }, "value", ...)) This is a bit harder to read than: !grep { !blah($_) } "value", ... but has the advantage of the ability to shortcut on the first item that fails. Similarly, to say "at least one subexpression must be true": defined(List::Util::first(sub { blah($_) }, "value", ...)) which can shortcut in contrast to: grep { blah($_) } "value", ... METHODSnew() => OBJCompilation data This subclass adds the following compilation data ($cd). Keys which contain compilation result: $c->comment($cd, @args) => STRGenerate 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) => RESULTAside from arguments known by the base class (Data::Sah::Compiler::Prog), this class supports these arguments:
$c->add_runtime_use($cd, $module [, \@import_terms ])This is like add_runtime_module(), but indicate that $module needs to be "use"-d in the generated code (for example, Perl pragmas). Normally if add_runtime_module() is used, the generated code will use "require". If you use "$c->add_runtime_use($cd, 'foo')", this code will be generated: use foo; If you use "$c->add_runtime_use($cd, 'foo', ["'a'", "'b'", "123"])", this code will be generated: use foo ('a', 'b', 123); If you use "$c->add_runtime_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_runtime_no($cd, $module [, \@import_terms ])This is the counterpart of add_runtime_use(), to generate "no foo" statement. See also: add_runtime_use(). $c->add_sun_module($cd)Add Scalar::Util::Numeric module, or Scalar::Util::Numeric::PP when "pp" compile argument is true. ENVIRONMENTDATA_SAH_PP => boolSet default for "pp" compile argument. DATA_SAH_CORE => boolSet default for "core" compile argument. DATA_SAH_CORE_OR_PP => boolSet default for "core_or_pp" compile argument. DATA_SAH_NO_MODULES => boolSet default for "no_modules" compile argument. HOMEPAGEPlease visit the project's homepage at <https://metacpan.org/release/Data-Sah>. SOURCESource repository is at <https://github.com/perlancar/perl-Data-Sah>. AUTHORperlancar <perlancar@cpan.org> CONTRIBUTINGTo contribute, you can send patches by email/via RT, or send pull requests on GitHub. Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: % prove -l If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. COPYRIGHT AND LICENSEThis software is copyright (c) 2024, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar <perlancar@cpan.org>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGSPlease report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Sah> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
|