line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package safenav; |
2
|
1
|
|
|
1
|
|
237189
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
403
|
use PerlX::SafeNav ('$safenav', '$unsafenav'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
169
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
*begin = *wrap = $safenav; |
7
|
|
|
|
|
|
|
*end = *unwrap = $unsafenav; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
1; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf-8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
safenav - Safe-navigation for Perl |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use safenav; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $tire_age = $car |
24
|
|
|
|
|
|
|
-> safenav::wrap() |
25
|
|
|
|
|
|
|
-> wheels() |
26
|
|
|
|
|
|
|
-> [0] # undef, if no wheels at all. |
27
|
|
|
|
|
|
|
-> tire() # undef, if no tire on the wheel. |
28
|
|
|
|
|
|
|
-> {created_on} |
29
|
|
|
|
|
|
|
-> delta_days($now) |
30
|
|
|
|
|
|
|
-> safenav::unwrap(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
unless (defined $tire_age) { |
33
|
|
|
|
|
|
|
# The car either have no wheels, or the first wheel has no tire. |
34
|
|
|
|
|
|
|
... |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This C pragma provides helper methods for wrapping a chain of calls and make it safe from encountering C values in the way. If any of sub-expressions yield C, instead of aborting the program with an error message, the entire chain yields C instead. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This pragma is part of L. It is just an alternative interface. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Say we have this chain, in which each part right after ther C<< -> >> operator may yield C: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$o->a()->{b}->c()->[42]->d(); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
To make it safe from C values, we mark the beginning and the end with C and C: |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$o-> safenav::wrap() -> a()->{b}->c()->[42]->d() -> safenav::unwrap(); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Or alternatively, with C and C: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$o-> safenav::begin() -> a()->{b}->c()->[42]->d() -> safenav::end(); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Whichever seems better for you. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SEE ALSO |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L, L |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |