Venus/Role/Boxable.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 96.3% 26 / 27 CC 2 SCAR 2.5
CC
2
Cov
100%
box
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Venus/Role/Tryable.pm ↑ Summary Venus/Role/Matchable.pm »
1 package Venus::Role::Boxable;
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 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # METHODS
11  
12 sub box {
13 3 ▶ my ($self, $method, @args) = @_;
Subroutine box: called CC=2 SCAR=6.9
Pod documented
14  
15 3 require Venus::Box;
16  
17 3 ▶ my $value = $method ? $self->$method(@args) : $self;
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 1 2 3
18  
19 3 return Venus::Box->new(value => $value);
20 }
21  
22 # EXPORTS
23  
24 sub EXPORT {
25 62 ▶ ['box']
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
26 }
27  
28 61 1;
29  
30  
31  
32 =head1 NAME
33  
34 Venus::Role::Boxable - Boxable Role
35  
36 =cut
37  
38 =head1 ABSTRACT
39  
40 Boxable Role for Perl 5
41  
42 =cut
43  
44 =head1 SYNOPSIS
45  
46 package Example;
47  
48 use Venus::Class;
49  
50 with 'Venus::Role::Boxable';
51  
52 attr 'text';
53  
54 package main;
55  
56 my $example = Example->new(text => 'hello, world');
57  
58 # $example->box('text')->lc->ucfirst->concat('.')->unbox->get;
59  
60 # "Hello, world."
61  
62 =cut
63  
64 =head1 DESCRIPTION
65  
66 This package modifies the consuming package and provides a method for boxing
67 itself. This makes it possible to chain method calls across objects and values.
68  
69 =cut
70  
71 =head1 METHODS
72  
73 This package provides the following methods:
74  
75 =cut
76  
77 =head2 box
78  
79 box(Str | CodeRef $method, Any @args) (Self)
80  
81 The box method returns the invocant boxed, i.e. encapsulated, using
82 L<Venus::Box>. This method supports dispatching, i.e. providing a method name
83 and arguments whose return value will be acted on by this method.
84  
85 I<Since C<0.01>>
86  
87 =over 4
88  
89 =item box example 1
90  
91 package main;
92  
93 my $example = Example->new(text => 'hello, world');
94  
95 my $box = $example->box;
96  
97 # bless({ value => bless(..., "Example") }, "Venus::Box")
98  
99 =back
100  
101 =over 4
102  
103 =item box example 2
104  
105 package main;
106  
107 my $example = Example->new(text => 'hello, world');
108  
109 my $box = $example->box('text');
110  
111 # bless({ value => bless(..., "Venus::String") }, "Venus::Box")
112  
113 # $example->box('text')->lc->ucfirst->concat('.')->unbox->get;
114  
115 =back
116  
117 =cut
« Venus/Role/Tryable.pm ↑ Summary Venus/Role/Matchable.pm »