| 1 | package Venus::Role::Valuable; | ||||||||||
| 2 | |||||||||||
| 3 | 96 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 96 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 96 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 96 | ▶ | use Venus::Role 'attr'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # ATTRIBUTES | ||||||||||
| 11 | |||||||||||
| 12 | 96 | attr 'value'; | |||||||||
| 13 | |||||||||||
| 14 | # BUILDERS | ||||||||||
| 15 | |||||||||||
| 16 | sub BUILD { | ||||||||||
| 17 | 8382 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 8382 | ▶ | $self->value($self->default) if !exists $data->{value}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | # METHODS | ||||||||||
| 23 | |||||||||||
| 24 | sub default { | ||||||||||
| 25 | |||||||||||
| 26 | 25 | ▶ | return; | ||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub get { | ||||||||||
| 30 | 35902 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | |||||||||||
| 32 | 35902 | return $self->value; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub set { | ||||||||||
| 36 | 5 | ▶ | my ($self, $value) = @_; | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | 5 | return $self->value($value); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # EXPORTS | ||||||||||
| 42 | |||||||||||
| 43 | sub EXPORT { | ||||||||||
| 44 | 265 | ▶ | ['default', 'get', 'set', 'value'] | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 96 | 1; | |||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | =head1 NAME | ||||||||||
| 52 | |||||||||||
| 53 | Venus::Role::Valuable - Valuable Role | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | =head1 ABSTRACT | ||||||||||
| 58 | |||||||||||
| 59 | Valuable Role for Perl 5 | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||
| 64 | |||||||||||
| 65 | package Example; | ||||||||||
| 66 | |||||||||||
| 67 | use Venus::Class; | ||||||||||
| 68 | |||||||||||
| 69 | with 'Venus::Role::Valuable'; | ||||||||||
| 70 | |||||||||||
| 71 | package main; | ||||||||||
| 72 | |||||||||||
| 73 | my $example = Example->new; | ||||||||||
| 74 | |||||||||||
| 75 | # $example->value; | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | =head1 DESCRIPTION | ||||||||||
| 80 | |||||||||||
| 81 | This package modifies the consuming package and provides a C<value> attribute | ||||||||||
| 82 | which defaults to what's returned by the C<default> method, as well as C<get> | ||||||||||
| 83 | and C<set> methods for modifying the value. | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | =head1 ATTRIBUTES | ||||||||||
| 88 | |||||||||||
| 89 | This package has the following attributes: | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | =head2 value | ||||||||||
| 94 | |||||||||||
| 95 | value(Any) | ||||||||||
| 96 | |||||||||||
| 97 | This attribute is read-write, accepts C<(Any)> values, and is optional. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | =head1 METHODS | ||||||||||
| 102 | |||||||||||
| 103 | This package provides the following methods: | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | =head2 default | ||||||||||
| 108 | |||||||||||
| 109 | default() (any) | ||||||||||
| 110 | |||||||||||
| 111 | The default method returns the default value, i.e. C<undef>. | ||||||||||
| 112 | |||||||||||
| 113 | I<Since C<0.01>> | ||||||||||
| 114 | |||||||||||
| 115 | =over 4 | ||||||||||
| 116 | |||||||||||
| 117 | =item default example 1 | ||||||||||
| 118 | |||||||||||
| 119 | package main; | ||||||||||
| 120 | |||||||||||
| 121 | my $example = Example->new; | ||||||||||
| 122 | |||||||||||
| 123 | my $default = $example->default; | ||||||||||
| 124 | |||||||||||
| 125 | # undef | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =cut | ||||||||||
| 130 | |||||||||||
| 131 | =head2 get | ||||||||||
| 132 | |||||||||||
| 133 | get() (any) | ||||||||||
| 134 | |||||||||||
| 135 | The get method gets and returns the value. | ||||||||||
| 136 | |||||||||||
| 137 | I<Since C<0.01>> | ||||||||||
| 138 | |||||||||||
| 139 | =over 4 | ||||||||||
| 140 | |||||||||||
| 141 | =item get example 1 | ||||||||||
| 142 | |||||||||||
| 143 | package main; | ||||||||||
| 144 | |||||||||||
| 145 | my $example = Example->new(value => 'hey, there'); | ||||||||||
| 146 | |||||||||||
| 147 | my $get = $example->get; | ||||||||||
| 148 | |||||||||||
| 149 | # "hey, there" | ||||||||||
| 150 | |||||||||||
| 151 | =back | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | =head2 set | ||||||||||
| 156 | |||||||||||
| 157 | set(any $value) (any) | ||||||||||
| 158 | |||||||||||
| 159 | The set method set the value and returns the value set. | ||||||||||
| 160 | |||||||||||
| 161 | I<Since C<0.01>> | ||||||||||
| 162 | |||||||||||
| 163 | =over 4 | ||||||||||
| 164 | |||||||||||
| 165 | =item set example 1 | ||||||||||
| 166 | |||||||||||
| 167 | package main; | ||||||||||
| 168 | |||||||||||
| 169 | my $example = Example->new(value => 'hey, there'); | ||||||||||
| 170 | |||||||||||
| 171 | my $set = $example->set('hi, there'); | ||||||||||
| 172 | |||||||||||
| 173 | # "hi, there" | ||||||||||
| 174 | |||||||||||
| 175 | =back | ||||||||||
| 176 | |||||||||||
| 177 | =cut | ||||||||||
| 178 | |||||||||||
| 179 | =head1 AUTHORS | ||||||||||
| 180 | |||||||||||
| 181 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 182 | |||||||||||
| 183 | =cut | ||||||||||
| 184 | |||||||||||
| 185 | =head1 LICENSE | ||||||||||
| 186 | |||||||||||
| 187 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 188 | |||||||||||
| 189 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 190 | the terms of the Apache license version 2.0. | ||||||||||
| 191 | |||||||||||
| 192 | =cut | ||||||||||