Venus/Role/Matchable.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%
match
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Venus/Role/Boxable.pm ↑ Summary Venus/Role/Pluggable.pm »
1 package Venus::Role::Matchable;
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 match {
13 4 ▶ my ($self, $method, @args) = @_;
Subroutine match: called CC=2 SCAR=6.9
Pod documented
14  
15 4 require Venus::Match;
16  
17 4 ▶ my $match = Venus::Match->new($method ? scalar($self->$method(@args)) : $self);
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 2 2 4
18  
19 4 return $match;
20 }
21  
22 # EXPORTS
23  
24 sub EXPORT {
25 62 ▶ ['match']
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::Matchable - Matchable Role
35  
36 =cut
37  
38 =head1 ABSTRACT
39  
40 Matchable 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::Matchable';
51  
52 attr 'active';
53  
54 sub validate {
55 my ($self) = @_;
56  
57 return $self->match->when('active')->then(true)->none(false);
58 }
59  
60 package main;
61  
62 my $example = Example->new;
63  
64 # $example->validate->result;
65  
66 # 0
67  
68 =cut
69  
70 =head1 DESCRIPTION
71  
72 This package modifies the consuming package and provides a mechanism for
73 assembling complex pattern matching operations.
74  
75 =cut
76  
77 =head1 METHODS
78  
79 This package provides the following methods:
80  
81 =cut
82  
83 =head2 match
84  
85 match(Str | CodeRef $method, Any @args) (Match)
86  
87 The match method returns a L<Venus::Match> object having the match value set to
88 the invocant or the result of a dispatch. This method supports dispatching,
89 i.e. providing a method name and arguments whose return value will be acted on
90 by this method.
91  
92 I<Since C<0.04>>
93  
94 =over 4
95  
96 =item match example 1
97  
98 package main;
99  
100 my $example = Example->new;
101  
102 my $match = $example->match;
103  
104 # bless({..., value => bless(..., 'Example')}, 'Venus::Match')
105  
106 =back
107  
108 =over 4
109  
110 =item match example 2
111  
112 package main;
113  
114 my $example = Example->new;
115  
116 my $match = $example->match('active');
117  
118 # bless({..., value => undef}, 'Venus::Match')
119  
120 =back
121  
122 =over 4
123  
124 =item match example 3
125  
126 package main;
127  
128 my $example = Example->new(active => 1);
129  
130 my $match = $example->match('active');
131  
132 # bless({..., value => 1}, 'Venus::Match')
133  
134 =back
135  
136 =cut
« Venus/Role/Boxable.pm ↑ Summary Venus/Role/Pluggable.pm »