vmod_constant(3)

Name
vmod_constant - constants for VCL

SYNOPSIS

            import constant [as name] [from "path"]

            new xacl = constant.acl([ACL init])

                ACL xacl.get([ACL fallback])

                BOOL xacl.defined()

            new xbackend = constant.backend([BACKEND init])

                BACKEND xbackend.get([BACKEND fallback])

                BOOL xbackend.defined()

            new xblob = constant.blob([BLOB init])

                BLOB xblob.get([BLOB fallback])

                BOOL xblob.defined()

            new xbody = constant.body([BODY init])

                BODY xbody.get([BODY fallback])

                BOOL xbody.defined()

            new xbool = constant.bool([BOOL init])

                BOOL xbool.get([BOOL fallback])

                BOOL xbool.defined()

            new xbytes = constant.bytes([BYTES init])

                BYTES xbytes.get([BYTES fallback])

                BOOL xbytes.defined()

            new xduration = constant.duration([DURATION init])

                DURATION xduration.get([DURATION fallback])

                BOOL xduration.defined()

            new xheader = constant.header([HEADER init])

                HEADER xheader.get([HEADER fallback])

                BOOL xheader.defined()

            new xint = constant.int([INT init])

                INT xint.get([INT fallback])

                BOOL xint.defined()

            new xip = constant.ip([IP init])

                IP xip.get([IP fallback])

                BOOL xip.defined()

            new xprobe = constant.probe([PROBE init])

                PROBE xprobe.get([PROBE fallback])

                BOOL xprobe.defined()

            new xreal = constant.real([REAL init])

                REAL xreal.get([REAL fallback])

                BOOL xreal.defined()

            new xstevedore = constant.stevedore([STEVEDORE init])

                STEVEDORE xstevedore.get([STEVEDORE fallback])

                BOOL xstevedore.defined()

            new xstring = constant.string([STRING init])

                STRING xstring.get([STRING fallback])

                BOOL xstring.defined()

            new xtime = constant.time([TIME init])

                TIME xtime.get([TIME fallback])

                BOOL xtime.defined()

DESCRIPTION

This module implements globally (per vcl) scoped constants as objects: All vcl subroutines have the same view on constants.

The value of a constant is the value assigned to it at construction time, if any.

constants are undefined if no value is assigned in the constructor.

Attempts to .get() an undefined value will return the .get() method`s fallback argument. For most types, there is a default fallback; if there is none, using .get() on an undefined value triggers a VCL failure at runtime.

Example:

            import constant;

            sub vcl_init {
             new xint = constant.int(42);
             new xundef = constant.int();
            }

            sub vcl_recv {
             set req.http.def = xundef.defined(); # false
             set req.http.fallback = xundef.get(5); # 5
            }

            sub vcl_deliver {
             set resp.http.the-answer = xint.get(); # 42
            }

The implementation of the various classes of this vmod is auto-generated, and so is the documentation. Thus, the documentation following this generic description is identical for all types except for the respective type names and the .get() fallback.

  new xacl = constant.acl([ACL init])

Construct a(n) ACL constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  ACL xacl.get([ACL fallback])

Return the value of the constant or the fallback argument if it is undefined. Using .get() on an undefined value without a fallback triggers a VCL error.

  BOOL xacl.defined()

Return whether the constant is defined.

  new xbackend = constant.backend([BACKEND init])

Construct a(n) BACKEND constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  BACKEND xbackend.get([BACKEND fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is the None backend.

  BOOL xbackend.defined()

Return whether the constant is defined.

  new xblob = constant.blob([BLOB init])

Construct a(n) BLOB constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  BLOB xblob.get([BLOB fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is the null blob.

  BOOL xblob.defined()

Return whether the constant is defined.

  new xbody = constant.body([BODY init])

Construct a(n) BODY constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  BODY xbody.get([BODY fallback])

Return the value of the constant or the fallback argument if it is undefined. Using .get() on an undefined value without a fallback triggers a VCL error.

  BOOL xbody.defined()

Return whether the constant is defined.

  new xbool = constant.bool([BOOL init])

Construct a(n) BOOL constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  BOOL xbool.get([BOOL fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is false

  BOOL xbool.defined()

Return whether the constant is defined.

  new xbytes = constant.bytes([BYTES init])

Construct a(n) BYTES constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  BYTES xbytes.get([BYTES fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is 0 bytes.

  BOOL xbytes.defined()

Return whether the constant is defined.

  new xduration = constant.duration([DURATION init])

Construct a(n) DURATION constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  DURATION xduration.get([DURATION fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is 0s.

  BOOL xduration.defined()

Return whether the constant is defined.

  new xheader = constant.header([HEADER init])

Construct a(n) HEADER constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  HEADER xheader.get([HEADER fallback])

Return the value of the constant or the fallback argument if it is undefined. Using .get() on an undefined value without a fallback triggers a VCL error.

  BOOL xheader.defined()

Return whether the constant is defined.

  new xint = constant.int([INT init])

Construct a(n) INT constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  INT xint.get([INT fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is 0.

  BOOL xint.defined()

Return whether the constant is defined.

  new xip = constant.ip([IP init])

Construct a(n) IP constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  IP xip.get([IP fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is IPv4 0.0.0.0.

  BOOL xip.defined()

Return whether the constant is defined.

  new xprobe = constant.probe([PROBE init])

Construct a(n) PROBE constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  PROBE xprobe.get([PROBE fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is no backend.

  BOOL xprobe.defined()

Return whether the constant is defined.

  new xreal = constant.real([REAL init])

Construct a(n) REAL constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  REAL xreal.get([REAL fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is 0.0.

  BOOL xreal.defined()

Return whether the constant is defined.

  new xstevedore = constant.stevedore([STEVEDORE init])

Construct a(n) STEVEDORE constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  STEVEDORE xstevedore.get([STEVEDORE fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is the default storage.

  BOOL xstevedore.defined()

Return whether the constant is defined.

  new xstring = constant.string([STRING init])

Construct a(n) STRING constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  STRING xstring.get([STRING fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is the empty string.

  BOOL xstring.defined()

Return whether the constant is defined.

  new xtime = constant.time([TIME init])

Construct a(n) TIME constant with the value init, if provided. If no init value is provided, the constant will be undefined.

  TIME xtime.get([TIME fallback])

Return the value of the constant or the fallback argument if it is undefined. The default fallback is the epoch (1970/1/1 0:00:00 GMT).

  BOOL xtime.defined()

Return whether the constant is defined.

SEE ALSO

vcl(7),vinyld(1)

COPYRIGHT

            Copyright 2018-2022 UPLEX Nils Goroll Systemoptimierung

            Redistribution and use in source and binary forms, with or without
            modification, are permitted provided that the following conditions are
            met:

            1. Redistributions of source code must retain the above copyright
               notice, this list of conditions and the following disclaimer.

            2. Redistributions in binary form must reproduce the above copyright
               notice, this list of conditions and the following disclaimer in the
               documentation and/or other materials provided with the
               distribution.

            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
            "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
            LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
            A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
            HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
            SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
            LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
            DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
            THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
            (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
            OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.