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
- get example 1
-
# given: synopsis
package main;
my $get = $atom->get;
# undef
- get example 2
-
# 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.
Since 3.55
- set example 1
-
# given: synopsis
package main;
my $set = $atom->set("hello");
# "hello"
- set example 2
-
# 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:
"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:
- operation:
"("")"
- This package overloads the "" operator.
example 1
# given: synopsis;
my $result = "$atom";
# ""
example 2
# given: synopsis;
$atom->set("hello");
my $result = "$atom";
# "hello"
- operation:
"(eq)"
- This package overloads the "eq"
operator.
example 1
# given: synopsis;
my $result = $atom eq "";
# 1
example 2
# given: synopsis;
$atom->set("hello");
my $result = $atom eq "hello";
# 1
- operation:
"(ne)"
- This package overloads the "ne"
operator.
example 1
# given: synopsis;
my $result = $atom ne "";
# 0
example 2
# given: synopsis;
$atom->set("hello");
my $result = $atom ne "";
# 1
- operation:
"(qr)"
- This package overloads the "qr"
operator.
example 1
# given: synopsis;
my $test = 'hello' =~ qr/$atom/;
# 1
Awncorp, "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.