blib/lib/Venus/Role/Matchable.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 96.4% 27 / 28 CC 2 SCAR 2.5
CC
2
Cov
100%
match
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Venus/Role/Tryable.pm ↑ Summary blib/lib/Venus/Role/Resultable.pm »
1 package Venus::Role::Matchable;
2  
3 119 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 119 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 119 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 119 ▶use Venus::Role 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # METHODS
13  
14 4 ▶sub match {
Subroutine match: called CC=2 SCAR=6.9
Pod documented
15 4 my ($self, $method, @args) = @_;
16  
17 4 require Venus::Match;
18  
19 4 local $_ = $self;
20  
21 4 ▶ my $match = Venus::Match->new($method ? scalar($self->$method(@args)) : $self);
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 2 2 4
22  
23 4 return $match;
24 }
25  
26 # EXPORTS
27  
28 120 ▶sub EXPORT {
Subroutine EXPORT: called CC=1 SCAR=0.0
Pod undocumented
29 120 ['match']
30 }
31  
32 119 1;
33  
34  
35  
36 =head1 NAME
37  
38 Venus::Role::Matchable - Matchable Role
39  
40 =cut
41  
42 =head1 ABSTRACT
43  
44 Matchable Role for Perl 5
45  
46 =cut
47  
48 =head1 SYNOPSIS
49  
50 package Example;
51  
52 use Venus::Class;
53  
54 with 'Venus::Role::Matchable';
55  
56 attr 'active';
57  
58 sub validate {
59 my ($self) = @_;
60  
61 return $self->match->when('active')->then(true)->none(false);
62 }
63  
64 package main;
65  
66 my $example = Example->new;
67  
68 # $example->validate->result;
69  
70 # 0
71  
72 =cut
73  
74 =head1 DESCRIPTION
75  
76 This package modifies the consuming package and provides a mechanism for
77 assembling complex pattern matching operations.
78  
79 =cut
80  
81 =head1 METHODS
82  
83 This package provides the following methods:
84  
85 =cut
86  
87 =head2 match
88  
89 match(string | coderef $method, any @args) (Venus::Match)
90  
91 The match method returns a L<Venus::Match> object having the match value set to
92 the invocant or the result of a dispatch. This method supports dispatching,
93 i.e. providing a method name and arguments whose return value will be acted on
94 by this method.
95  
96 I<Since C<0.04>>
97  
98 =over 4
99  
100 =item match example 1
101  
102 package main;
103  
104 my $example = Example->new;
105  
106 my $match = $example->match;
107  
108 # bless({..., value => bless(..., 'Example')}, 'Venus::Match')
109  
110 =back
111  
112 =over 4
113  
114 =item match example 2
115  
116 package main;
117  
118 my $example = Example->new;
119  
120 my $match = $example->match('active');
121  
122 # bless({..., value => undef}, 'Venus::Match')
123  
124 =back
125  
126 =over 4
127  
128 =item match example 3
129  
130 package main;
131  
132 my $example = Example->new(active => 1);
133  
134 my $match = $example->match('active');
135  
136 # bless({..., value => 1}, 'Venus::Match')
137  
138 =back
139  
140 =cut
141  
142 =head1 AUTHORS
143  
144 Awncorp, C<awncorp@cpan.org>
145  
146 =cut
147  
148 =head1 LICENSE
149  
150 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
151  
152 This program is free software, you can redistribute it and/or modify it under
153 the terms of the Apache license version 2.0.
154  
155 =cut
« blib/lib/Venus/Role/Tryable.pm ↑ Summary blib/lib/Venus/Role/Resultable.pm »