Badger::Constants(3pm)

Badger::Constants3pm

Defines constants for other badger modules

Usage

    use Badger::Constants 'HASH';
    
    if (ref $something eq HASH) {
        # rejoice!  No need to quote the word 'HASH'
    }

Overview

This module defines a number of constants used by other "Badger" modules. They can be imported into the caller's namespace by naming them as options to the "use Badger::Constants" statement:

    use Badger::Constants 'HASH';
    print HASH;   # HASH

Alternatively, one of the tagset identifiers may be specified to import different sets of constants.

    use Badger::Constants ':types';
    print HASH;   # HASH

Exportable constants

Constants

Set to "Badger::Constants".

Scalar

The literal word "SCALAR", typically used for testing references.

    if (ref $data eq SCALAR) {
        ...
    }

Array

The literal word "ARRAY", typically used for testing references.

    if (ref $data eq ARRAY) {
        ...
    }

Hash

The literal word "HASH", typically used for testing references.

    if (ref $data eq HASH) {
        ...
    }

Code

The literal word "CODE", typically used for testing references.

    if (ref $data eq CODE) {
        ...
    }

Glob

The literal word "GLOB", typically used for testing references.

    if (ref $data eq GLOB) {
        ...
    }

Regex

The literal word "Regexp", typically used for testing references.

    if (ref $data eq REGEX) {
        ...
    }

False

A false value (0)

True

A true value (1)

Off

A generic flag used to disable things (0).

On

A generic flag used to enable things (1).

All

The literal string "all".

None

The literal string "none".

Default

The literal string "default".

Warn

The literal string "warn".

Last

The value "-1", used to index the last item in an array.

    $array[LAST];

CRLF

An unambiguous carriage return and newline sequence: "\015\012"

PKG

An alias for the "::" symbol used to delimiter Perl packages. Typically used to construct symbol references.

    use Badger::Constants 'PKG';
    use constant EXAMPLE => 'EXAMPLE';
    
    my $var = ${ $pkg.PKG.EXAMPLE };   # same as: ${"${pkg}::EXAMPLE"}

Dot

An alias for a dot ".".

Refs

The literal string "refs". Typically used like so:

    no strict REFS;

Once

The literal string "once". Typically used like so:

    no warnings ONCE;

Blank

An empty string. How much more blank could this be? And the answer is none. None more blank.

Space

A single space character. Not to be confused with the three dimensional fabric of reality that it happens to share a name with.

Slash

A forward slash as used to separate path segments in URIs and filesystem paths on sane operating systems.

Delimiter

A regular expression used to split whitespace delimited tokens. Also accepts commas with optional trailing whitespace as a delimiter.

    $names = [ split DELIMITER, $names ] 
        unless ref $names eq ARRAY;

Wildcard

A regular expression used to match strings containing the "*" or "?" wildcard characters.

    if ($path =~ WILDCARD) {
        # do something...
    }

UTF8

The literal string "utf8".

Json

The literal string "json".

Yaml

The literal string "yaml".

Loaded

Contains the literal string "BADGER_LOADED". The Badger::Class module uses it to define the $BADGER_LOADED variable in any modules that it loads.

Exportable tag sets

The following tag sets and associated constants are defined:

:types

    SCALAR HASH ARRAY CODE REGEX

:values

    FALSE TRUE OFF ON ALL NONE DEFAULT

:all

All the constants.

Author

Andy Wardley <http://wardley.org/>

From libbadger-perl 0.16-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.