line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Role::Matchable; |
2
|
|
|
|
|
|
|
|
3
|
87
|
|
|
87
|
|
1475
|
use 5.018; |
|
87
|
|
|
|
|
309
|
|
4
|
|
|
|
|
|
|
|
5
|
87
|
|
|
87
|
|
451
|
use strict; |
|
87
|
|
|
|
|
202
|
|
|
87
|
|
|
|
|
2207
|
|
6
|
87
|
|
|
87
|
|
497
|
use warnings; |
|
87
|
|
|
|
|
206
|
|
|
87
|
|
|
|
|
2526
|
|
7
|
|
|
|
|
|
|
|
8
|
87
|
|
|
87
|
|
511
|
use Venus::Role 'with'; |
|
87
|
|
|
|
|
252
|
|
|
87
|
|
|
|
|
588
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# METHODS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub match { |
13
|
4
|
|
|
4
|
1
|
13
|
my ($self, $method, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
|
|
537
|
require Venus::Match; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
9
|
local $_ = $self; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
26
|
my $match = Venus::Match->new($method ? scalar($self->$method(@args)) : $self); |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
24
|
return $match; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# EXPORTS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub EXPORT { |
27
|
88
|
|
|
88
|
0
|
344
|
['match'] |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
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(Str | CodeRef $method, Any @args) (Match) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The match method returns a L 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> |
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 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
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 |