Venus::Atom - Atom Class
Atom Class for Perl 5
package main; use Venus::Atom; my $atom = Venus::Atom->new; # $atom->get; # undef
This package provides a write-once object representing a constant value.
This package inherits behaviors from:
Venus::Sealed
This package provides the following methods:
get() (any)
The get method can be used to get the underlying constant value set during instantiation.
Since 3.55
3.55
# given: synopsis package main; my $get = $atom->get; # undef
# given: synopsis package main; $atom->set("hello"); my $get = $atom->get; # "hello"
set(any $data) (any)
The set method can be used to set the underlying constant value set during instantiation or via this method. An atom can only be set once, either at instantiation of via this method. Any attempt to re-set the atom will result in an error.
# given: synopsis package main; my $set = $atom->set("hello"); # "hello"
# given: synopsis package main; my $set = $atom->set("hello"); $atom->set("hello"); # Exception! (isa Venus::Atom::Error) (see error_on_set)
This package may raise the following errors:
error_on_set
This package may raise an error_on_set exception.
example 1
# given: synopsis; my $input = { throw => 'error_on_set', value => 'test', }; my $error = $atom->catch('error', $input); # my $name = $error->name; # "on_set" # my $message = $error->render; # "Can't re-set atom value to \"test\"" # my $value = $error->stash('value'); # "test"
This package overloads the following operators:
("")
This package overloads the "" operator.
""
# given: synopsis; my $result = "$atom"; # ""
example 2
# given: synopsis; $atom->set("hello"); my $result = "$atom"; # "hello"
(eq)
This package overloads the eq operator.
eq
# given: synopsis; my $result = $atom eq ""; # 1
# given: synopsis; $atom->set("hello"); my $result = $atom eq "hello"; # 1
(ne)
This package overloads the ne operator.
ne
# given: synopsis; my $result = $atom ne ""; # 0
# given: synopsis; $atom->set("hello"); my $result = $atom ne ""; # 1
(qr)
This package overloads the qr operator.
qr
# given: synopsis; my $test = 'hello' =~ qr/$atom/; # 1
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2022, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.