GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Sah::Compiler::perl(3) User Contributed Perl Documentation Data::Sah::Compiler::perl(3)

Data::Sah::Compiler::perl - Compile Sah schema to Perl code

This document describes version 0.917 of Data::Sah::Compiler::perl (from Perl distribution Data-Sah), released on 2024-02-16.

 # see Data::Sah

Derived from Data::Sah::Compiler::Prog.

Set default for "pp" compile argument. Takes precedence over environment "DATA_SAH_PP".

Set default for "core" compile argument. Takes precedence over environment "DATA_SAH_CORE".

Set default for "core_or_pp" compile argument. Takes precedence over environment "DATA_SAH_CORE_OR_PP".

Set default for "no_modules" compile argument. Takes precedence over environment "DATA_SAH_NO_MODULES".

To 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", ...

new() => OBJ

Compilation data

This subclass adds the following compilation data ($cd).

Keys which contain compilation result:

$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 arguments known by the base class (Data::Sah::Compiler::Prog), this class supports these arguments:

  • pp

    Bool, default false. If set to true, will avoid the use of XS modules in the generated code and will opt instead to use pure-perl modules.

  • core

    Bool, default false. If set to true, will avoid the use of non-core modules in the generated code and will opt instead to use core modules.

  • core_or_pp

    Bool, default false. If set to true, will stick to using only core or PP modules in the generated code.

  • whitelist_modules

    Array of str. When "pp"/"core"/"core_or_pp" option is set to true, the use of non-appropriate modules will cause failure. However, you can pass a list of modules that are allowed nevertheless.

$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().

Add Scalar::Util::Numeric module, or Scalar::Util::Numeric::PP when "pp" compile argument is true.

Set default for "pp" compile argument.

Set default for "core" compile argument.

Set default for "core_or_pp" compile argument.

Set default for "no_modules" compile argument.

Please visit the project's homepage at <https://metacpan.org/release/Data-Sah>.

Source repository is at <https://github.com/perlancar/perl-Data-Sah>.

perlancar <perlancar@cpan.org>

To 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.

This 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.

Please 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.

2024-02-16 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.