line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Venus::Role::Tryable; |
2
|
|
|
|
|
|
|
|
3
|
87
|
|
|
87
|
|
1561
|
use 5.018; |
|
87
|
|
|
|
|
638
|
|
4
|
|
|
|
|
|
|
|
5
|
87
|
|
|
87
|
|
443
|
use strict; |
|
87
|
|
|
|
|
166
|
|
|
87
|
|
|
|
|
1726
|
|
6
|
87
|
|
|
87
|
|
417
|
use warnings; |
|
87
|
|
|
|
|
157
|
|
|
87
|
|
|
|
|
2345
|
|
7
|
|
|
|
|
|
|
|
8
|
87
|
|
|
87
|
|
456
|
use Venus::Role 'with'; |
|
87
|
|
|
|
|
182
|
|
|
87
|
|
|
|
|
548
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# METHODS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub try { |
13
|
3082
|
|
|
3082
|
1
|
11213
|
my ($self, $callback, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
3082
|
|
|
|
|
86543
|
require Venus::Try; |
16
|
|
|
|
|
|
|
|
17
|
3082
|
|
|
|
|
24755
|
my $try = Venus::Try->new(invocant => $self, arguments => [@args]); |
18
|
|
|
|
|
|
|
|
19
|
3082
|
50
|
|
|
|
9530
|
return $try if !$callback; |
20
|
|
|
|
|
|
|
|
21
|
3082
|
|
|
|
|
11289
|
return $try->call($callback); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# EXPORTS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub EXPORT { |
27
|
176
|
|
|
176
|
0
|
567
|
['try'] |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Venus::Role::Tryable - Tryable Role |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 ABSTRACT |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Tryable Role for Perl 5 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package Example; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Venus::Class 'with'; |
51
|
|
|
|
|
|
|
use Venus 'raise'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
with 'Venus::Role::Tryable'; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub test { |
56
|
|
|
|
|
|
|
raise 'Example::Error'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
package main; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $example = Example->new; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# $example->try('test'); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This package modifies the consuming package and provides a mechanism for |
70
|
|
|
|
|
|
|
handling potentially volatile routines. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This package provides the following methods: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 try |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
try(Str | CodeRef $method, Any @args) (Try) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The try method returns a L object having the invocant, callback, |
85
|
|
|
|
|
|
|
arguments pre-configured. This method supports dispatching, i.e. providing a |
86
|
|
|
|
|
|
|
method name and arguments whose return value will be acted on by this method. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
I> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item try example 1 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
package main; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $example = Example->new; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $try = $example->try('test'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# my $value = $try->result; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHORS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Awncorp, C |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Copyright (C) 2000, Al Newkirk. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
117
|
|
|
|
|
|
|
the terms of the Apache license version 2.0. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |