File Coverage

blib/lib/Venus/Role/Matchable.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 2 50.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Venus::Role::Matchable;
2              
3 96     96   1686 use 5.018;
  96         341  
4              
5 96     96   552 use strict;
  96         217  
  96         2815  
6 96     96   589 use warnings;
  96         217  
  96         4063  
7              
8 96     96   663 use Venus::Role 'with';
  96         231  
  96         674  
9              
10             # METHODS
11              
12             sub match {
13 4     4 1 18 my ($self, $method, @args) = @_;
14              
15 4         581 require Venus::Match;
16              
17 4         22 local $_ = $self;
18              
19 4 100       32 my $match = Venus::Match->new($method ? scalar($self->$method(@args)) : $self);
20              
21 4         33 return $match;
22             }
23              
24             # EXPORTS
25              
26             sub EXPORT {
27 97     97 0 386 ['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(string | coderef $method, any @args) (Venus::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, Awncorp, C.
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