| 1 | package Venus::Role::Boxable; | ||||||||||
| 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 'with'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # METHODS | ||||||||||
| 11 | |||||||||||
| 12 | sub box { | ||||||||||
| 13 | 2 | ▶ | my ($self, $method, @args) = @_; | ||||||||
|
Subroutine
box: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | require Venus::Box; | |||||||||
| 16 | |||||||||||
| 17 | 2 | local $_ = $self; | |||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | my $value = $method ? $self->$method(@args) : $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 2 | return Venus::Box->new(value => $value); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | # EXPORTS | ||||||||||
| 25 | |||||||||||
| 26 | sub EXPORT { | ||||||||||
| 27 | 97 | ▶ | ['box'] | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 96 | 1; | |||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | =head1 NAME | ||||||||||
| 35 | |||||||||||
| 36 | Venus::Role::Boxable - Boxable Role | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | =head1 ABSTRACT | ||||||||||
| 41 | |||||||||||
| 42 | Boxable Role for Perl 5 | ||||||||||
| 43 | |||||||||||
| 44 | =cut | ||||||||||
| 45 | |||||||||||
| 46 | =head1 SYNOPSIS | ||||||||||
| 47 | |||||||||||
| 48 | package Example; | ||||||||||
| 49 | |||||||||||
| 50 | use Venus::Class; | ||||||||||
| 51 | |||||||||||
| 52 | with 'Venus::Role::Boxable'; | ||||||||||
| 53 | |||||||||||
| 54 | attr 'text'; | ||||||||||
| 55 | |||||||||||
| 56 | package main; | ||||||||||
| 57 | |||||||||||
| 58 | my $example = Example->new(text => 'hello, world'); | ||||||||||
| 59 | |||||||||||
| 60 | # $example->box('text')->lc->ucfirst->concat('.')->unbox->get; | ||||||||||
| 61 | |||||||||||
| 62 | # "Hello, world." | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | =head1 DESCRIPTION | ||||||||||
| 67 | |||||||||||
| 68 | This package modifies the consuming package and provides a method for boxing | ||||||||||
| 69 | itself. This makes it possible to chain method calls across objects and values. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | =head1 METHODS | ||||||||||
| 74 | |||||||||||
| 75 | This package provides the following methods: | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | =head2 box | ||||||||||
| 80 | |||||||||||
| 81 | box(string | coderef $method, any @args) (object) | ||||||||||
| 82 | |||||||||||
| 83 | The box method returns the invocant boxed, i.e. encapsulated, using | ||||||||||
| 84 | L<Venus::Box>. This method supports dispatching, i.e. providing a method name | ||||||||||
| 85 | and arguments whose return value will be acted on by this method. | ||||||||||
| 86 | |||||||||||
| 87 | I<Since C<0.01>> | ||||||||||
| 88 | |||||||||||
| 89 | =over 4 | ||||||||||
| 90 | |||||||||||
| 91 | =item box example 1 | ||||||||||
| 92 | |||||||||||
| 93 | package main; | ||||||||||
| 94 | |||||||||||
| 95 | my $example = Example->new(text => 'hello, world'); | ||||||||||
| 96 | |||||||||||
| 97 | my $box = $example->box; | ||||||||||
| 98 | |||||||||||
| 99 | # bless({ value => bless(..., "Example") }, "Venus::Box") | ||||||||||
| 100 | |||||||||||
| 101 | =back | ||||||||||
| 102 | |||||||||||
| 103 | =over 4 | ||||||||||
| 104 | |||||||||||
| 105 | =item box example 2 | ||||||||||
| 106 | |||||||||||
| 107 | package main; | ||||||||||
| 108 | |||||||||||
| 109 | my $example = Example->new(text => 'hello, world'); | ||||||||||
| 110 | |||||||||||
| 111 | my $box = $example->box('text'); | ||||||||||
| 112 | |||||||||||
| 113 | # bless({ value => bless(..., "Venus::String") }, "Venus::Box") | ||||||||||
| 114 | |||||||||||
| 115 | # $example->box('text')->lc->ucfirst->concat('.')->unbox->get; | ||||||||||
| 116 | |||||||||||
| 117 | =back | ||||||||||
| 118 | |||||||||||
| 119 | =cut | ||||||||||
| 120 | |||||||||||
| 121 | =head1 AUTHORS | ||||||||||
| 122 | |||||||||||
| 123 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | =head1 LICENSE | ||||||||||
| 128 | |||||||||||
| 129 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 130 | |||||||||||
| 131 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 132 | the terms of the Apache license version 2.0. | ||||||||||
| 133 | |||||||||||
| 134 | =cut | ||||||||||