Acme-constant

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

  Change: 0d546f48b16280c1abbcfc046f760d5a9c2f353c
  Author: Konrad Borowski <glitchmr@myopera.com>
  Date : 2013-09-21 10:10:19 +0000

    Release Acme-constant 0.1.1. 

  Change: 4a9266d9edc838e7337fae90828514978df91dbb
  Author: Konrad Borowski <glitchmr@myopera.com>
  Date : 2013-09-21 10:09:45 +0000

    Change error messages to be in Perl-style, and add diagnostics. 

  Change: 0eb944c3f28b22ed4a1686e563df41e6cb4772fa
  Author: Konrad Borowski <glitchmr@myopera.com>
  Date : 2013-09-21 09:41:41 +0000

    Support OLD Perl versions by returning value after croak.

    Perl isn't clever enough to notice croak throws exception and thinks
    it has to return a value. Now fake value is returned as lvalue - the
    only way to access it however is modifying `Carp::croak` to not throw

lib/Acme/constant.pm  view on Meta::CPAN

        # user wants an array. The !defined wantarray check is intended
        # to detect use of wantarray() in void context.
        if (wantarray || !defined wantarray) {
            @values;
        }
        # When constant has one element, writing to it in scalar
        # context is fine.
        elsif (@values == 1) {
            $values[0];
        }
        # This shows an error, as otherwise, this could cause a strange
        # situation where scalar A shows (A)[0], when A has one
        # element, and 2 when A has two elements. The behavior of Array
        # constructor in ECMAScript is already confusing enough (new
        # Array(3) is [,,,], but new Array(3, 3) is [3, 3]).
        else {
            Carp::croak "Can't call ${package}::$name in scalar context";

            # Return lvalue in order to make older versions of Perl
            # happy, even when it's not going to be used.
            @values;

lib/Acme/constant.pm  view on Meta::CPAN


You can also use directly use C<import> method, in order to
conditionally load constant.

    BEGIN {
        require Acme::constant;
        Acme::constant->import(DEBUG => 1) if $ENV{DEBUG};
    }

Howver, usually the good idea to declare constant anyway, as using
undefined constants in strict mode causes Perl errors (and sometimes
could be parsed incorrectly).

    use Acme::constant DEBUG => $ENV{DEBUG};

Constants belong to the package they were defined in. When you declare
constant in some module, the constant is subroutine declared in it.
However, it's possible to export constants with module such as
L<Exporter>, just as you would export standard subroutine.

    package Some::Package;

lib/Acme/constant.pm  view on Meta::CPAN

mean, you have to disambiguate your call. If you want to get count of
elements, you may want to assign it to C<()>, like C<() = CONSTANT>. If
you want to get last element, use C<(CONSTANT)[-1]>.

=item Can't modify non-lvalue subroutine call

(F) You tried to assign single value to constant containing an array.
This won't work, as Perl expects a list to be assigned. If you really
want to assign an single element, use C<(CONSTANT) = $value> syntax.

This error is provided by Perl, and as such, it could be confusing,
as constant actually is lvalue, just assigned in wrong context.

=item Useless localization of subroutine entry

(W syntax) You tried to localize constant with C<local> operator. This
is legal, but currently has no effect. This may change in some future
version of Perl, but in the meantime such code is discouraged.

=item Useless use of "Acme::constant" pragma



( run in 0.352 second using v1.01-cache-2.11-cpan-65fba6d93b7 )