NAME

Venus::Role::Accessible - Accessible Role

ABSTRACT

Accessible Role for Perl 5

SYNOPSIS

package Example;

use Venus::Class;

with 'Venus::Role::Accessible';

attr 'value';

sub downcase {
  lc $_[0]->value
}

sub upcase {
  uc $_[0]->value
}

package main;

my $example = Example->new(value => 'hello, there');

# $example->value;

DESCRIPTION

This package modifies the consuming package and provides the access method for getting and setting attributes.

METHODS

This package provides the following methods:

access

access(Str $name, Any $value) (Any)

The access method gets or sets the class attribute specified.

Since 1.23

access example 1
# given: synopsis

package main;

my $access = $example->access;

# undef
access example 2
# given: synopsis

package main;

my $access = $example->access('value');

# "hello, there"
access example 3
# given: synopsis

package main;

my $access = $example->access('value', 'something');

# "something"
access example 4
# given: synopsis

package main;

my $instance = $example;

# bless({}, "Example")

$example->access('value', 'something');

# "something"

$instance = $example;

# bless({value => "something"}, "Example")

assign

assign(Str $name, Str | CodeRef $code, Any @args) (Any)

The assign method dispatches the method call or executes the callback, sets the class attribute specified to the result, and returns the result.

Since 1.23

assign example 1
# given: synopsis

package main;

my $assign = $example->assign('value', 'downcase');

# "hello, there"
assign example 2
# given: synopsis

package main;

my $assign = $example->assign('value', 'upcase');

# "HELLO, THERE"
assign example 3
# given: synopsis

package main;

my $instance = $example;

# bless({value => "hello, there"}, "Example")

my $assign = $example->assign('value', 'downcase');

# "hello, there"

$instance = $example;

# bless({value => "hello, there"}, "Example")