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 SCAR 6.9
CC
2
Cov
100%
match
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Venus/Role/Boxable.pm ↑ Summary /dev/null »
1 package Venus::Role::Matchable;
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 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 local $_ = $self;
18  
19 4 ▶ my $match = Venus::Match->new($method ? scalar($self->$method(@args)) : $self);
Branch: 1 branch
BranchTrueFalseTotal
$method ? : 2 2 4
20  
21 4 return $match;
22 }
23  
24 # EXPORTS
25  
26 sub EXPORT {
27 97 ▶ ['match']
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::Matchable - Matchable Role
37  
38 =cut
39  
40 =head1 ABSTRACT
41  
42 Matchable 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::Matchable';
53  
54 attr 'active';
55  
56 sub validate {
57 my ($self) = @_;
58  
59 return $self->match->when('active')->then(true)->none(false);
60 }
61  
62 package main;
63  
64 my $example = Example->new;
65  
66 # $example->validate->result;
67  
68 # 0
69  
70 =cut
71  
72 =head1 DESCRIPTION
73  
74 This package modifies the consuming package and provides a mechanism for
75 assembling complex pattern matching operations.
76  
77 =cut
78  
79 =head1 METHODS
80  
81 This package provides the following methods:
82  
83 =cut
84  
85 =head2 match
86  
87 match(string | coderef $method, any @args) (Venus::Match)
88  
89 The match method returns a L<Venus::Match> object having the match value set to
90 the invocant or the result of a dispatch. This method supports dispatching,
91 i.e. providing a method name and arguments whose return value will be acted on
92 by this method.
93  
94 I<Since C<0.04>>
95  
96 =over 4
97  
98 =item match example 1
99  
100 package main;
101  
102 my $example = Example->new;
103  
104 my $match = $example->match;
105  
106 # bless({..., value => bless(..., 'Example')}, 'Venus::Match')
107  
108 =back
109  
110 =over 4
111  
112 =item match example 2
113  
114 package main;
115  
116 my $example = Example->new;
117  
118 my $match = $example->match('active');
119  
120 # bless({..., value => undef}, 'Venus::Match')
121  
122 =back
123  
124 =over 4
125  
126 =item match example 3
127  
128 package main;
129  
130 my $example = Example->new(active => 1);
131  
132 my $match = $example->match('active');
133  
134 # bless({..., value => 1}, 'Venus::Match')
135  
136 =back
137  
138 =cut
139  
140 =head1 AUTHORS
141  
142 Awncorp, C<awncorp@cpan.org>
143  
144 =cut
145  
146 =head1 LICENSE
147  
148 Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>.
149  
150 This program is free software, you can redistribute it and/or modify it under
151 the terms of the Apache license version 2.0.
152  
153 =cut
« blib/lib/Venus/Role/Boxable.pm ↑ Summary /dev/null »