line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Monad::Either; |
2
|
1
|
|
|
1
|
|
15902
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
413
|
use parent qw/Data::Monad::Base::Monad/; |
|
1
|
|
|
|
|
254
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
38
|
use Exporter qw/import/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
281
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/left right/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub left { |
10
|
3
|
|
|
3
|
1
|
380
|
return bless [@_], __PACKAGE__ . '::Left'; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub right { |
14
|
7
|
|
|
7
|
1
|
904
|
return bless [@_], __PACKAGE__ . '::Right'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# from Data::Monad::Base::Monad |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub unit { |
20
|
0
|
|
|
0
|
1
|
0
|
my ($class, @v) = @_; |
21
|
0
|
|
|
|
|
0
|
return right(@v); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub flat_map { |
25
|
6
|
|
|
6
|
1
|
38
|
my ($self, $f) = @_; |
26
|
6
|
100
|
|
|
|
11
|
return $self->is_left ? $self : $f->($self->value); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# instance methods |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub is_left { |
32
|
9
|
|
|
9
|
1
|
35
|
my ($self) = @_; |
33
|
9
|
|
|
|
|
30
|
return ref($self) eq __PACKAGE__ . '::Left'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub is_right { |
37
|
2
|
|
|
2
|
1
|
18
|
my ($self) = @_; |
38
|
2
|
|
|
|
|
8
|
return ref($self) eq __PACKAGE__ . '::Right'; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub value { |
42
|
10
|
|
|
10
|
1
|
14
|
my ($self) = @_; |
43
|
10
|
100
|
|
|
|
45
|
return wantarray ? @$self : $self->[0]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package Data::Monad::Either::Left; |
47
|
1
|
|
|
1
|
|
4
|
use parent -norequire, 'Data::Monad::Either'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package Data::Monad::Either::Right; |
50
|
1
|
|
|
1
|
|
46
|
use parent -norequire, 'Data::Monad::Either'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |