| 1 | package Venus::Role::Valuable; | ||||||||||
| 2 | |||||||||||
| 3 | 61 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 61 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 61 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 61 | ▶ | use Venus::Role 'attr'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # ATTRIBUTES | ||||||||||
| 11 | |||||||||||
| 12 | 61 | attr 'value'; | |||||||||
| 13 | |||||||||||
| 14 | # BUILDERS | ||||||||||
| 15 | |||||||||||
| 16 | sub BUILD { | ||||||||||
| 17 | 4631 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 4631 | ▶ | $self->value($self->default) if !exists $data->{value}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | # METHODS | ||||||||||
| 23 | |||||||||||
| 24 | sub default { | ||||||||||
| 25 | 10 | ▶ | return; | ||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | # EXPORTS | ||||||||||
| 29 | |||||||||||
| 30 | sub EXPORT { | ||||||||||
| 31 | 87 | ▶ | ['value', 'default'] | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 61 | 1; | |||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | Venus::Role::Valuable - Valuable Role | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | =head1 ABSTRACT | ||||||||||
| 45 | |||||||||||
| 46 | Valuable Role for Perl 5 | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | =head1 SYNOPSIS | ||||||||||
| 51 | |||||||||||
| 52 | package Example; | ||||||||||
| 53 | |||||||||||
| 54 | use Venus::Class; | ||||||||||
| 55 | |||||||||||
| 56 | with 'Venus::Role::Valuable'; | ||||||||||
| 57 | |||||||||||
| 58 | package main; | ||||||||||
| 59 | |||||||||||
| 60 | my $example = Example->new; | ||||||||||
| 61 | |||||||||||
| 62 | # $example->value; | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | =head1 DESCRIPTION | ||||||||||
| 67 | |||||||||||
| 68 | This package modifies the consuming package and provides a C<value> attribute | ||||||||||
| 69 | which defaults to what's returned by the C<default> method. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | =head1 ATTRIBUTES | ||||||||||
| 74 | |||||||||||
| 75 | This package has the following attributes: | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | =head2 value | ||||||||||
| 80 | |||||||||||
| 81 | value(Any) | ||||||||||
| 82 | |||||||||||
| 83 | This attribute is read-write, accepts C<(Any)> values, and is optional. | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | =head1 METHODS | ||||||||||
| 88 | |||||||||||
| 89 | This package provides the following methods: | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | =head2 default | ||||||||||
| 94 | |||||||||||
| 95 | default() (Any) | ||||||||||
| 96 | |||||||||||
| 97 | The default method returns the default value, i.e. C<undef>. | ||||||||||
| 98 | |||||||||||
| 99 | I<Since C<0.01>> | ||||||||||
| 100 | |||||||||||
| 101 | =over 4 | ||||||||||
| 102 | |||||||||||
| 103 | =item default example 1 | ||||||||||
| 104 | |||||||||||
| 105 | package main; | ||||||||||
| 106 | |||||||||||
| 107 | my $example = Example->new; | ||||||||||
| 108 | |||||||||||
| 109 | my $default = $example->default; | ||||||||||
| 110 | |||||||||||
| 111 | # undef | ||||||||||
| 112 | |||||||||||
| 113 | =back | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||