line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
11
|
|
|
11
|
|
964035
|
use 5.014; |
|
11
|
|
|
|
|
65
|
|
2
|
11
|
|
|
11
|
|
70
|
use strict; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
217
|
|
3
|
11
|
|
|
11
|
|
54
|
use warnings; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
236
|
|
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
51
|
use Carp (); |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
139
|
|
6
|
11
|
|
|
11
|
|
4819
|
use Devel::StrictMode (); |
|
11
|
|
|
|
|
4784
|
|
|
11
|
|
|
|
|
247
|
|
7
|
11
|
|
|
11
|
|
70
|
use Scalar::Util (); |
|
11
|
|
|
|
|
32
|
|
|
11
|
|
|
|
|
531
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package results; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
12
|
|
|
|
|
|
|
our $VERSION = '0.006'; |
13
|
|
|
|
|
|
|
|
14
|
11
|
|
|
11
|
|
4704
|
use Exporter::Shiny qw( err is_result ok ok_list ); |
|
11
|
|
|
|
|
43525
|
|
|
11
|
|
|
|
|
110
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw( err ok ); |
16
|
|
|
|
|
|
|
|
17
|
11
|
|
|
11
|
|
7513
|
use Attribute::Handlers; |
|
11
|
|
|
|
|
56573
|
|
|
11
|
|
|
|
|
72
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
require Result::Err; |
20
|
|
|
|
|
|
|
require Result::Ok; |
21
|
|
|
|
|
|
|
require Result::OkList; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use constant { |
24
|
11
|
|
|
|
|
3243
|
ERR_CLASS => 'Result::Err', |
25
|
|
|
|
|
|
|
OK_CLASS => 'Result::Ok', |
26
|
|
|
|
|
|
|
OK_LIST_CLASS => 'Result::OkList', |
27
|
11
|
|
|
11
|
|
747
|
}; |
|
11
|
|
|
|
|
27
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub err { |
30
|
50
|
50
|
|
50
|
1
|
11961
|
Carp::croak("Void context forbidden here") unless defined wantarray; |
31
|
50
|
|
|
|
|
274
|
ERR_CLASS->new( @_ ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_result { |
35
|
11
|
100
|
66
|
11
|
1
|
7390
|
Scalar::Util::blessed( $_[0] ) |
36
|
|
|
|
|
|
|
and $_[0]->can( 'DOES' ) |
37
|
|
|
|
|
|
|
and $_[0]->DOES( 'Result::Trait' ) |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub ok { |
41
|
59
|
50
|
|
59
|
1
|
436374
|
Carp::croak("Void context forbidden here") unless defined wantarray; |
42
|
59
|
|
|
|
|
282
|
OK_CLASS->new( @_ ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub ok_list { |
46
|
1
|
50
|
|
1
|
1
|
5631
|
Carp::croak("Void context forbidden here") unless defined wantarray; |
47
|
1
|
|
|
|
|
13
|
OK_LIST_CLASS->new( @_ ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub UNIVERSAL::Result : ATTR(CODE) { |
51
|
2
|
|
|
2
|
0
|
52370
|
Devel::StrictMode::STRICT or return; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
8
|
my ( $package, $symbol, $referent, $attr, $data ) = @_; |
54
|
2
|
|
|
|
|
4
|
my $name = *{$symbol}{NAME}; |
|
2
|
|
|
|
|
5
|
|
55
|
|
|
|
|
|
|
|
56
|
11
|
|
|
11
|
|
111
|
no strict 'refs'; |
|
11
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
493
|
|
57
|
11
|
|
|
11
|
|
77
|
no warnings 'redefine'; |
|
11
|
|
|
|
|
65
|
|
|
11
|
|
|
|
|
2983
|
|
58
|
|
|
|
|
|
|
|
59
|
2
|
100
|
|
|
|
11
|
if ( ref($data) eq 'ARRAY' ) { |
60
|
1
|
|
|
|
|
5
|
require Type::Utils; |
61
|
1
|
|
|
|
|
10
|
my $type = Type::Utils::dwim_type( $data->[0], for => $package ); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
11
|
*{"$package\::$name"} = sub { |
64
|
4
|
|
|
4
|
|
776
|
my $return = $referent->( @_ ); |
65
|
4
|
100
|
|
|
|
18
|
die "Function '$name' declared to return a Result, but returned: $return" |
66
|
|
|
|
|
|
|
unless is_result( $return ); |
67
|
3
|
|
|
|
|
70
|
$return->type( $type ); |
68
|
1
|
|
|
|
|
62321
|
}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
1
|
|
|
|
|
6
|
*{"$package\::$name"} = sub { |
72
|
3
|
|
|
3
|
|
7085
|
my $return = $referent->( @_ ); |
73
|
3
|
100
|
|
|
|
42
|
die "Function '$name' declared to return a Result, but returned: $return" |
74
|
|
|
|
|
|
|
unless is_result( $return ); |
75
|
2
|
|
|
|
|
55
|
$return; |
76
|
1
|
|
|
|
|
6
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
11
|
|
|
11
|
|
110
|
} |
|
11
|
|
|
|
|
31
|
|
|
11
|
|
|
|
|
74
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |