line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Python::Serialize::Pickle::InlinePython; |
2
|
3
|
|
|
3
|
|
1432
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
110
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
178
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
4160
|
use Inline Python => <<'...'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
from pickle import Pickler, Unpickler |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
def __pickler(fname): |
10
|
|
|
|
|
|
|
return Pickler(open(fname, 'wb')) |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
def __unpickler(fname): |
13
|
|
|
|
|
|
|
return Unpickler(open(fname, 'rb')) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
def __load(unp): |
16
|
|
|
|
|
|
|
try: |
17
|
|
|
|
|
|
|
return unp.load() |
18
|
|
|
|
|
|
|
except EOFError: |
19
|
|
|
|
|
|
|
return "EOFErrorEOFErrorEOFErrorEOFError" # wtf? |
20
|
|
|
|
|
|
|
... |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
my ($class, $fname) = @_; |
24
|
|
|
|
|
|
|
if ($fname =~ s/^>//g) { |
25
|
|
|
|
|
|
|
bless { pickler => __pickler($fname) }, 'Python::Serialize::Pickle::InlinePython'; |
26
|
|
|
|
|
|
|
} else { |
27
|
|
|
|
|
|
|
bless { unpickler => __unpickler($fname) }, 'Python::Serialize::Pickle::InlinePython'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub dump { |
32
|
|
|
|
|
|
|
my ($self, $stuff) = @_; |
33
|
|
|
|
|
|
|
die "this is not a writer-obj" unless $self->{pickler}; |
34
|
|
|
|
|
|
|
$self->{pickler}->dump($stuff); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
die "this is not a reader-obj" unless $self->{unpickler}; |
40
|
|
|
|
|
|
|
my $ret = __load($self->{unpickler}); |
41
|
|
|
|
|
|
|
if ($ret eq 'EOFErrorEOFErrorEOFErrorEOFError') { |
42
|
|
|
|
|
|
|
return undef; ## no critic |
43
|
|
|
|
|
|
|
} else { |
44
|
|
|
|
|
|
|
return $ret; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub close { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
delete $self->{$_} for keys %$self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |