/
Storable.pod
1933 lines (1341 loc) · 62.5 KB
/
Storable.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=encoding euc-jp
=head1 NAME
=begin original
Storable - persistence for Perl data structures
=end original
Storable - Perl データ構造体の永続化
=head1 SYNOPSIS
use Storable;
store \%table, 'file';
$hashref = retrieve('file');
use Storable qw(nstore store_fd nstore_fd freeze thaw dclone);
=begin original
# Network order
nstore \%table, 'file';
$hashref = retrieve('file'); # There is NO nretrieve()
=end original
# ネットワーク順序
nstore \%table, 'file';
$hashref = retrieve('file'); # There is NO nretrieve()
=begin original
# Storing to and retrieving from an already opened file
store_fd \@array, \*STDOUT;
nstore_fd \%table, \*STDOUT;
$aryref = fd_retrieve(\*SOCKET);
$hashref = fd_retrieve(\*SOCKET);
=end original
# 既にオープンされているファイルへ格納し、取り込みます
store_fd \@array, \*STDOUT;
nstore_fd \%table, \*STDOUT;
$aryref = fd_retrieve(\*SOCKET);
$hashref = fd_retrieve(\*SOCKET);
=begin original
# Serializing to memory
$serialized = freeze \%table;
%table_clone = %{ thaw($serialized) };
=end original
# メモリへの直列化
$serialized = freeze \%table;
%table_clone = %{ thaw($serialized) };
=begin original
# Deep (recursive) cloning
$cloneref = dclone($ref);
=end original
# 深い(再帰的な)複写
$cloneref = dclone($ref);
=begin original
# Advisory locking
use Storable qw(lock_store lock_nstore lock_retrieve)
lock_store \%table, 'file';
lock_nstore \%table, 'file';
$hashref = lock_retrieve('file');
=end original
# アドバイザリロック
use Storable qw(lock_store lock_nstore lock_retrieve)
lock_store \%table, 'file';
lock_nstore \%table, 'file';
$hashref = lock_retrieve('file');
=head1 DESCRIPTION
=begin original
The Storable package brings persistence to your Perl data structures
containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be
conveniently stored to disk and retrieved at a later time.
=end original
Storable パッケージは、スカラ(SCALAR)、配列(ARRAY)、ハッシュ(HASH)、
オブジェクトのリファレンス(REF)を持った Perl のデータ構造体を永続化します。
つまり簡単にディスクに格納し、後で取り込むことを可能にします。
=begin original
It can be used in the regular procedural way by calling C<store> with
a reference to the object to be stored, along with the file name where
the image should be written.
=end original
格納するオブジェクトへのリファレンスとイメージが書き込まれるファイル名を
指定して C<store> を呼び出すという、通常の手続き的な方法で使うことが出来ます。
=begin original
The routine returns C<undef> for I/O problems or other internal error,
a true value otherwise. Serious errors are propagated as a C<die> exception.
=end original
そのルーチンは I/O 障害や他の内部エラーが発生すると C<undef> を返し、
そうでなければ真の値を返します。
重大なエラーは C<die> 例外で伝えられます。
=begin original
To retrieve data stored to disk, use C<retrieve> with a file name.
The objects stored into that file are recreated into memory for you,
and a I<reference> to the root object is returned. In case an I/O error
occurs while reading, C<undef> is returned instead. Other serious
errors are propagated via C<die>.
=end original
ディスクに格納されたデータを取り込むには、ファイル名を付けて C<retrieve> を
使います。
そしてそのファイルに格納されたオブジェクトはメモリ上に再生成されます。
元になるオブジェクトへのI<リファレンス>が返されます。
読込の途中でI/O エラーが発生すると、C<undef> が代わりに返されます。
他の重大なエラーの場合には、エラーが C<die> を通じて伝えられます。
=begin original
Since storage is performed recursively, you might want to stuff references
to objects that share a lot of common data into a single array or hash
table, and then store that object. That way, when you retrieve back the
whole thing, the objects will continue to share what they originally shared.
=end original
格納が再帰的に行われるので、共通のデータの多くを共有しているオブジェクトへの
リファレンスたちを1つの配列またはハッシュテーブルに詰め込んでしまい、
そのオブジェクトを格納したいと思うかもしれません。
この方法では、全体を
取り込んだときに、元々共有していたものを引き続き共有します。
=begin original
At the cost of a slight header overhead, you may store to an already
opened file descriptor using the C<store_fd> routine, and retrieve
from a file via C<fd_retrieve>. Those names aren't imported by default,
so you will have to do that explicitly if you need those routines.
The file descriptor you supply must be already opened, for read
if you're going to retrieve and for write if you wish to store.
=end original
ヘッダにちょっと手をいれると、C<store_fd> ルーチンを使って既に開いている
ファイル記述子に格納し、C<fd_retrieve> を通じてファイルから
取り出すことができます。
それらの名前はデフォルトではインポートされません。
そのため、これらのルーチンが必要であれば、明示的に
インポートしなければいけません。
指定するファイル記述子は、取り込むつもりであれば読み込み (read) で、
格納するつもりであれば書き込み (write) で、既に開かれていなければなりません。
store_fd(\%table, *STDOUT) || die "can't store to stdout\n";
$hashref = fd_retrieve(*STDIN);
=begin original
You can also store data in network order to allow easy sharing across
multiple platforms, or when storing on a socket known to be remotely
connected. The routines to call have an initial C<n> prefix for I<network>,
as in C<nstore> and C<nstore_fd>. At retrieval time, your data will be
correctly restored so you don't have to know whether you're restoring
from native or network ordered data. Double values are stored stringified
to ensure portability as well, at the slight risk of loosing some precision
in the last decimals.
=end original
複数のプラットフォームで共有することを簡単にしたり、リモートに
接続されていることが分かっているソケットに格納するときに、ネットワーク様式で
格納することも出来ます。
呼び出すルーチンには C<nstore> と C<nstore_fd> のように、頭に I<network> を
表す C<n> が付きます。
取り込むときはデータが正しく元に戻るので、取り込むのがネイティブからなのか、
ネットワーク様式のデータからなのかを知る必要はありません。
double(倍精度浮動小数点数型)の値も移植性が保証されるように
文字列化されます。
ただし最後の桁の精度が若干失われる危険性があります。
=begin original
When using C<fd_retrieve>, objects are retrieved in sequence, one
object (i.e. one recursive tree) per associated C<store_fd>.
=end original
C<retrieve_fd> を使うとき、オブジェクトは、対応する C<store_fd> 毎、
一つのオブジェクト(つまり一つの再帰ツリー)を順番に取り込まれます。
=begin original
If you're more from the object-oriented camp, you can inherit from
Storable and directly store your objects by invoking C<store> as
a method. The fact that the root of the to-be-stored tree is a
blessed reference (i.e. an object) is special-cased so that the
retrieve does not provide a reference to that object but rather the
blessed object reference itself. (Otherwise, you'd get a reference
to that blessed object).
=end original
さらにオブジェクト指向陣営寄りであれば、Storable を継承して、
C<store> をメソッドとして呼び出すことにより、あなたのオブジェクトを
直接格納することができます。
格納されるツリーの元が bless された
リファレンス(つまりオブジェクト)であれば、特別なケースになります。
そのため取込は、そのオブジェクトへのリファレンスを提供せず、
bless されたオブジェクトリファレンスを提供します。
(そうでなければ、そのblessされたオブジェクトへのリファレンスを
取得することにでしょう)
=head1 MEMORY STORE
(メモリへの格納)
=begin original
The Storable engine can also store data into a Perl scalar instead, to
later retrieve them. This is mainly used to freeze a complex structure in
some safe compact memory place (where it can possibly be sent to another
process via some IPC, since freezing the structure also serializes it in
effect). Later on, and maybe somewhere else, you can thaw the Perl scalar
out and recreate the original complex structure in memory.
=end original
Storable エンジンは後から取り込むために、Perl スカラにデータを
格納することもできます。
これは主に複雑な構造体を安全で小さなメモリ空間に固めるため(freeze)に
使われます(構造体を固めると実際には直列化もされるので、他のプロセスに
IPC を通じて送ることも潜在的には可能です)。
後で、そして多分どこか別のところで、Perl スカラを解凍(thaw)し、
元の複雑な構造体をメモリ上に再生成することができます。
=begin original
Surprisingly, the routines to be called are named C<freeze> and C<thaw>.
If you wish to send out the frozen scalar to another machine, use
C<nfreeze> instead to get a portable image.
=end original
驚いたことに、呼ばれるルーチンの名前は C<freeze> と C<thaw> といいます。
もし固めたスカラを他のマシンに送信したければ、代わりに C<nfreeze> を
ポータブルなイメージを取得してください。
=begin original
Note that freezing an object structure and immediately thawing it
actually achieves a deep cloning of that structure:
=end original
オブジェクト構造を固め、すぐに解凍すると、実際には、その構造を深く
複写することを実現していることに注意して下さい:
dclone(.) = thaw(freeze(.))
=begin original
Storable provides you with a C<dclone> interface which does not create
that intermediary scalar but instead freezes the structure in some
internal memory space and then immediately thaws it out.
=end original
Storable は、中間のスカラを作成することなく、代わりに内部メモリ空間に
構造を固め、すぐに解凍する C<dclone> インターフェイスを提供しています。
=head1 ADVISORY LOCKING
(アドバイザリロック)
=begin original
The C<lock_store> and C<lock_nstore> routine are equivalent to
C<store> and C<nstore>, except that they get an exclusive lock on
the file before writing. Likewise, C<lock_retrieve> does the same
as C<retrieve>, but also gets a shared lock on the file before reading.
=end original
C<lock_store> と C<lock_nstore> は C<store> と C<nstore> と同じです。
ただし、書き込む前に占有ロックを行います。
同様に C<lock_retrieve> は C<retrieve> のように動きます。
しかし読み込む前に共有ロックを行います。
=begin original
As with any advisory locking scheme, the protection only works if you
systematically use C<lock_store> and C<lock_retrieve>. If one side of
your application uses C<store> whilst the other uses C<lock_retrieve>,
you will get no protection at all.
=end original
全てのアドバイザリロックのスキームと同じように、保護はあなたが
システマティックに C<lock_store> と C<lock_retrieve> を使うときにだけ
機能します。
もし他の部分が C<lock_retrieve> を使っているときに、あなたの
アプリケーションのある部分が C<store> を使うと、何も保護されません。
=begin original
The internal advisory locking is implemented using Perl's flock()
routine. If your system does not support any form of flock(), or if
you share your files across NFS, you might wish to use other forms
of locking by using modules such as LockFile::Simple which lock a
file using a filesystem entry, instead of locking the file descriptor.
=end original
アドバイザリロックの内部は Perl の flock() ルーチンを使って実装されます。
もしあなたのシステムが flock() のいかなる形式もサポートしていなかったり、
あなたのファイルを NFS 越しにファイルを共有しているのであれば、
ファイル記述子ではなくファイルシステムのエントリを使ってロックする
LockFile:Simple のようなモジュールを使って他の形式のロックを
使いたいことでしょう。
=head1 SPEED
(スピード)
=begin original
The heart of Storable is written in C for decent speed. Extra low-level
optimizations have been made when manipulating perl internals, to
sacrifice encapsulation for the benefit of greater speed.
=end original
スピードを上げるため、Storable の中核部分は C で書かれています。
Perl 内部を操作するとき、よりスピードを上げるためにカプセル化を
犠牲にするという、特別な低レベルの最適化がなされています。
=head1 CANONICAL REPRESENTATION
(規範形式)
=begin original
Normally, Storable stores elements of hashes in the order they are
stored internally by Perl, i.e. pseudo-randomly. If you set
C<$Storable::canonical> to some C<TRUE> value, Storable will store
hashes with the elements sorted by their key. This allows you to
compare data structures by comparing their frozen representations (or
even the compressed frozen representations), which can be useful for
creating lookup tables for complicated queries.
=end original
通常 Storable はハッシュを Perl が内部的に格納している順序で要素を格納します。
つまり疑似ランダムになります。
もし C<$Storable::canonical> を C<TRUE> 値に設定すると、
Storable はハッシュをそのキーの順に要素を格納します。
これにより、データ構造体を固められた形式で(または固められ圧縮された
形式でさえ)比較することができるようになります。
これは複雑な問い合わせのための参照テーブルを作るのに便利でしょう。
=begin original
Canonical order does not imply network order; those are two orthogonal
settings.
=end original
規範様式(=Canonical)はネットワーク様式を意味していません。
それらはまったく違う設定です。
=head1 CODE REFERENCES
(コードリファレンス)
=begin original
Since Storable version 2.05, CODE references may be serialized with
the help of L<B::Deparse>. To enable this feature, set
C<$Storable::Deparse> to a true value. To enable deserialization,
C<$Storable::Eval> should be set to a true value. Be aware that
deserialization is done through C<eval>, which is dangerous if the
Storable file contains malicious data. You can set C<$Storable::Eval>
to a subroutine reference which would be used instead of C<eval>. See
below for an example using a L<Safe> compartment for deserialization
of CODE references.
=end original
Storable バージョン 2.05 から、コード(CODE)リファレンスが L<B::Deparse> の
助けを借りて直列化できます。
この機能を有効にするためには、C<$Storable::Deparse> を true 値に
設定してください。
非直列化を有効にするためには、C<$Storable::Eval> が true 値に
設定されていなければなりません。
非直列化が C<eval> を通して行われることに注意してください。
もし Storable ファイルに悪意のあるデータが入っていると危険です。
C<$Storable::Eval> に C<eval> の代わりに使われるサブルーチンリファレンスを
設定することができます。
コード(CODE)リファレンスの非直列化については、L<Safe> コンポーネントを
使っている下記の例をご覧ください。
=begin original
If C<$Storable::Deparse> and/or C<$Storable::Eval> are set to false
values, then the value of C<$Storable::forgive_me> (see below) is
respected while serializing and deserializing.
=end original
C<$Storable::Deparse> や C<$Storable::Eval> が偽の値に設定されると、
C<$Storable::forgive_me> (後述) の値は直列化や逆直列化中に反映されます。
=head1 FORWARD COMPATIBILITY
(将来への互換性)
=begin original
This release of Storable can be used on a newer version of Perl to
serialize data which is not supported by earlier Perls. By default,
Storable will attempt to do the right thing, by C<croak()>ing if it
encounters data that it cannot deserialize. However, the defaults
can be changed as follows:
=end original
今回の Storable のリリースでは、Perl のより新しいバージョンで以前の Perl では
サポートされていなかったデータを直列化するために使うことができます。
デフォルトでは Storable は適切なことをしようとし、非直列化できない
データにぶつかったら C<croak()> します。
しかしデフォルトは以下のように変更することができます:
=over 4
=item utf8 data
(utf8データ)
=begin original
Perl 5.6 added support for Unicode characters with code points > 255,
and Perl 5.8 has full support for Unicode characters in hash keys.
Perl internally encodes strings with these characters using utf8, and
Storable serializes them as utf8. By default, if an older version of
Perl encounters a utf8 value it cannot represent, it will C<croak()>.
To change this behaviour so that Storable deserializes utf8 encoded
values as the string of bytes (effectively dropping the I<is_utf8> flag)
set C<$Storable::drop_utf8> to some C<TRUE> value. This is a form of
data loss, because with C<$drop_utf8> true, it becomes impossible to tell
whether the original data was the Unicode string, or a series of bytes
that happen to be valid utf8.
=end original
Perl 5.6 は 255 よりも大きなコード値を持つ Unicode 文字のサポートが
加わりました。
そして Perl 5.8 では、ハッシュキーでのフルサポートを持ちます。
Perl は内部的に、これらの文字を持つ文字列を utf8 を使ってエンコードします。
Storable は utf8 として、それらを直列化します。
デフォルトでは、より古いバージョンがそれが表すことが出来ない utf8 の値に
ぶつかると、それは C<croak()> します。
Storable が utf8 をバイトの文字列としてエンコードされたものとして
非直列化するよう、この動きを変更するためには、$C<Storable::drop_utf8> を
何らかの C<TRUE> の値に設定してください。
これはデータが失われることになります。
というのも C<$drop_utf8> が true であると、もとのデータが
Unicode 文字列だったのか、たまたま utf8 として正しいバイトの
並びだったのかが分からなくなってしまいます。
=item restricted hashes
(限定ハッシュ)
=begin original
Perl 5.8 adds support for restricted hashes, which have keys
restricted to a given set, and can have values locked to be read only.
By default, when Storable encounters a restricted hash on a perl
that doesn't support them, it will deserialize it as a normal hash,
silently discarding any placeholder keys and leaving the keys and
all values unlocked. To make Storable C<croak()> instead, set
C<$Storable::downgrade_restricted> to a C<FALSE> value. To restore
the default set it back to some C<TRUE> value.
=end original
Perl 5.8 は限定ハッシュ(restricted hash) のサポートを追加します。
それは与えられた集合にのみキーが制限され、値を読込のみに
ロックすることが出来ます。
デフォルトではそれらをサポートしていない perl では Storable が
限定ハッシュにぶつかると、それを通常のハッシュとして非直列化します。
場所を保持するためのキーを全て黙って処分し、キーと値のロックを全て外します。
代わりに Storable に C<croak()> させるためには、
C<$Storable::downgrade_restricted> を C<FALSE> の値に設定してください。
デフォルトの設定に戻すためには何らかの C<TRUE> 値に戻してください。
=item files from future versions of Storable
(将来のバージョンの Storable からのファイル)
=begin original
Earlier versions of Storable would immediately croak if they encountered
a file with a higher internal version number than the reading Storable
knew about. Internal version numbers are increased each time new data
types (such as restricted hashes) are added to the vocabulary of the file
format. This meant that a newer Storable module had no way of writing a
file readable by an older Storable, even if the writer didn't store newer
data types.
=end original
以前の Storable は、読んでいる Storable が知っているものより高い
内部バージョンを持ったファイルにぶつかるとすぐに croak しました。
内部バージョン番号は新しいデータ型(限定ハッシュのような)がファイル形式の
用語に加えられるたびに上がります。
これはより新しい Storable モジュールには、たとえ新しいデータ型を
格納しなかったとしても、古い Storable で読めるようなファイルを書く方法が
ないことを意味します。
=begin original
This version of Storable will defer croaking until it encounters a data
type in the file that it does not recognize. This means that it will
continue to read files generated by newer Storable modules which are careful
in what they write out, making it easier to upgrade Storable modules in a
mixed environment.
=end original
Storable のこのバージョンは、ファイルの中で、それが理解しないデータ型に
ぶつかるまで croak しないという点で異なります。
つまりこれは出力するものに注意を払えば、新しい Storable モジュールで作られた
ファイルでも読むことが出来るということです。
これにより混在する環境で Storable をアップグレードすることが簡単になります。
=begin original
The old behaviour of immediate croaking can be re-instated by setting
C<$Storable::accept_future_minor> to some C<FALSE> value.
=end original
C<$Storable::accept_future_minor> を C<FALSE> 値にすることにより、即座に
croak するという Storable の古い動きに戻すことが出来ます。
=back
=begin original
All these variables have no effect on a newer Perl which supports the
relevant feature.
=end original
これらの変数は関連する機能をサポートしている新しい Perl では何の効果も
ありません。
=head1 ERROR REPORTING
(エラーレポート)
=begin original
Storable uses the "exception" paradigm, in that it does not try to workaround
failures: if something bad happens, an exception is generated from the
caller's perspective (see L<Carp> and C<croak()>). Use eval {} to trap
those exceptions.
=end original
Storable は"例外"パラダイムを使っています。
それでは障害を回避しようとはしません:
何かよくないことが発生したら、呼び出した側の視点で例外が発生します
(L<Carp> と C<croak()> をご覧ください)。
それらの例外を捕らえるために eval {} を使ってください。
=begin original
When Storable croaks, it tries to report the error via the C<logcroak()>
routine from the C<Log::Agent> package, if it is available.
=end original
Storable が croak するとき、C<Log::Agent> パッケージが利用できるのであれば、
その C<logcroak()> ルーチンを経由してエラーを報告しようとします。
=begin original
Normal errors are reported by having store() or retrieve() return C<undef>.
Such errors are usually I/O errors (or truncated stream errors at retrieval).
=end original
通常のエラーは storable() や retrieve() に C<undef> を返すことにより
報告されます。
そのようなエラーは通常 I/O のエラー(あるいは retrieve の際にストリームが
切り捨てられたか)です。
=head1 WIZARDS ONLY
(上級者のみ)
=head2 Hooks
(フック)
=begin original
Any class may define hooks that will be called during the serialization
and deserialization process on objects that are instances of that class.
Those hooks can redefine the way serialization is performed (and therefore,
how the symmetrical deserialization should be conducted).
=end original
全てのクラスで、そのクラスのインスタンスを直列化や非直列化の処理の途中で
呼ばれるフックを定義することもできます。
それらのフックは実行される直列化を実行する方法を再定義することが出来ます。
(そのため、対になる非直列化も、そのように振舞わなければなりません)
=begin original
Since we said earlier:
=end original
前述の通り:
dclone(.) = thaw(freeze(.))
=begin original
everything we say about hooks should also hold for deep cloning. However,
hooks get to know whether the operation is a mere serialization, or a cloning.
=end original
フックについて述べたことはすべて、深いクローン作成にも当てはまります。
しかしフックには、その処理が単なるシリライゼーションなのかクローンなのかが
わかります。
=begin original
Therefore, when serializing hooks are involved,
=end original
このため、直列化のフックが呼び出されるとになります。
dclone(.) <> thaw(freeze(.))
=begin original
Well, you could keep them in sync, but there's no guarantee it will always
hold on classes somebody else wrote. Besides, there is little to gain in
doing so: a serializing hook could keep only one attribute of an object,
which is probably not what should happen during a deep cloning of that
same object.
=end original
同期を取ることもできます。
しかし誰か他の人が書いたクラスについて常に当てはまるような保証はありません。
さらに、そうすることによって得られるものはあまりありません: 直列化のフックは、
あるオブジェクトの一つの属性を保持することだけができます。
それは、その同じオブジェクトの深い複写の間に起きることとは多分、違います。
=begin original
Here is the hooking interface:
=end original
以下にフックのインターフェイスを示します:
=over 4
=item C<STORABLE_freeze> I<obj>, I<cloning>
=begin original
The serializing hook, called on the object during serialization. It can be
inherited, or defined in the class itself, like any other method.
=end original
直列化フック。
オブジェクトが直列化されるときに呼ばれます。
これは他のメソッドと同様に継承したり、クラスの中で再定義することができます。
=begin original
Arguments: I<obj> is the object to serialize, I<cloning> is a flag indicating
whether we're in a dclone() or a regular serialization via store() or freeze().
=end original
引数: I<obj> は直列化するオブジェクト、I<cloning> は dclone() の
中であるか、store() や freeze() を経由した通常の直列化かを示します。
=begin original
Returned value: A LIST C<($serialized, $ref1, $ref2, ...)> where $serialized
is the serialized form to be used, and the optional $ref1, $ref2, etc... are
extra references that you wish to let the Storable engine serialize.
=end original
戻り値:リスト C<($serialized, $ref1, $ref2, ...) >。
$serialized は、使われる直列化された形式、オプションの $ref1, $ref2 などは、
Storable エンジンに直列化させたい特別なリファレンスです。
=begin original
At deserialization time, you will be given back the same LIST, but all the
extra references will be pointing into the deserialized structure.
=end original
非直列化のときには、あなたは同じリスト(LIST)が与えられます。
しかし特別なリファレンスは全て非直列化された構造体を示します。
=begin original
The B<first time> the hook is hit in a serialization flow, you may have it
return an empty list. That will signal the Storable engine to further
discard that hook for this class and to therefore revert to the default
serialization of the underlying Perl data. The hook will again be normally
processed in the next serialization.
=end original
B<最初に> フックが直列化の流れの中でヒットしたとき、あなたは空のリストを
返すことができます。
それはこのクラスのためのフックを、それから先、捨てらるよう Storable エンジンに
合図し、このため元になっている Perl データのデフォルトの直列化に戻ります。
そのフックは次の直列化では再び通常通り処理されます。
=begin original
Unless you know better, serializing hook should always say:
=end original
よく分からなければ、直列化のフックは以下のようにするべきです:
=begin original
sub STORABLE_freeze {
my ($self, $cloning) = @_;
return if $cloning; # Regular default serialization
....
}
=end original
sub STORABLE_freeze {
my ($self, $cloning) = @_;
return if $cloning; # 通常のデフォルトの直列化
....
}
=begin original
in order to keep reasonable dclone() semantics.
=end original
dclone() の意味論でも合理的になるようにします。
=item C<STORABLE_thaw> I<obj>, I<cloning>, I<serialized>, ...
=begin original
The deserializing hook called on the object during deserialization.
But wait: if we're deserializing, there's no object yet... right?
=end original
オブジェクトが非直列化されるときに呼ばれる非直列化フック。
しかし待ってください: もし非直列化しているのであれば、
オブジェクトはまだないのでは...?
=begin original
Wrong: the Storable engine creates an empty one for you. If you know Eiffel,
you can view C<STORABLE_thaw> as an alternate creation routine.
=end original
違います: Storable エンジンはあなたのために空のものを生成します。
Eiffel をご存知であれば、C<STORABLE_thaw> は代替生成ルーチンとして
みることが出来ます。
=begin original
This means the hook can be inherited like any other method, and that
I<obj> is your blessed reference for this particular instance.
=end original
つまり、フックは他のメソッドと同じように継承することができ、
C<obj> はこの特定のインスタンスのための bless されたリファレンスになります。
=begin original
The other arguments should look familiar if you know C<STORABLE_freeze>:
I<cloning> is true when we're part of a deep clone operation, I<serialized>
is the serialized string you returned to the engine in C<STORABLE_freeze>,
and there may be an optional list of references, in the same order you gave
them at serialization time, pointing to the deserialized objects (which
have been processed courtesy of the Storable engine).
=end original
その他の引数は C<STORABLE_freeze> を知っていれば慣れているでしょう: 深い
クローン処理の一部であれば I<cloning> は真になります。
I<serialized> は I<STORABLE_freeze> でエンジンに返した直列化された
文字列です。
そしてオプションのリファレンスのリストもあるかもしれません。
それはシリアル化のときにあなたが与えた順番で、非直列化された
オブジェクトを指します(それらは Storable エンジンによって特別に扱われます)。
=begin original
When the Storable engine does not find any C<STORABLE_thaw> hook routine,
it tries to load the class by requiring the package dynamically (using
the blessed package name), and then re-attempts the lookup. If at that
time the hook cannot be located, the engine croaks. Note that this mechanism
will fail if you define several classes in the same file, but L<perlmod>
warned you.
=end original
Storable エンジンが何も C<STORABLE_thaw> フックルーチンを見つけられなければ、
それは動的にパッケージを(bless されたパッケージ名を使って)
require することによりロードしようとします。
そして再び参照しようとします。
もしこの時点でフックが見つからなければ、エンジンは croak します。
この仕組は同じファイルでいくつものクラスを定義しているとうまくいきません。
しかし L<perlmod> が警告するでしょう。
=begin original
It is up to you to use this information to populate I<obj> the way you want.
=end original
これらの情報を使って、どのように I<obj> を作成するかは、あなた次第です。
=begin original
Returned value: none.
=end original
戻り値: ありません。
=item C<STORABLE_attach> I<class>, I<cloning>, I<serialized>
=begin original
While C<STORABLE_freeze> and C<STORABLE_thaw> are useful for classes where
each instance is independent, this mechanism has difficulty (or is
incompatible) with objects that exist as common process-level or
system-level resources, such as singleton objects, database pools, caches
or memoized objects.
=end original
C<STORABLE_freeze> と C<STORABLE_thaw> は、それぞれのインスタンスが
独立しているクラスには有用ですが、この機構は、
シングルトンオブジェクト、データベースプール、キャッシュ、メモ化
オブジェクトのような、プロセスレベルやシステムレベルで共通のリソースとして
存在しているオブジェクトについては問題(や非互換性)があります。
=begin original
The alternative C<STORABLE_attach> method provides a solution for these
shared objects. Instead of C<STORABLE_freeze> --E<gt> C<STORABLE_thaw>,
you implement C<STORABLE_freeze> --E<gt> C<STORABLE_attach> instead.
=end original
代替物である C<STORABLE_attach> メソッドは、これらの共有オブジェクトのための
解法を提供します。
C<STORABLE_freeze> --E<gt> C<STORABLE_thaw> の代わりに、
C<STORABLE_freeze> --E<gt> C<STORABLE_attach> を実装します。
=begin original
Arguments: I<class> is the class we are attaching to, I<cloning> is a flag
indicating whether we're in a dclone() or a regular de-serialization via
thaw(), and I<serialized> is the stored string for the resource object.
=end original
引数: I<class> はアタッチしたクラス、I<cloning> は今 dclone() や
thaw() 経由の正規逆直列化の中にいるかを示すフラグ、
I<serialized> リソースオブジェクトのための保管した文字列です。
=begin original
Because these resource objects are considered to be owned by the entire
process/system, and not the "property" of whatever is being serialized,
no references underneath the object should be included in the serialized
string. Thus, in any class that implements C<STORABLE_attach>, the
C<STORABLE_freeze> method cannot return any references, and C<Storable>
will throw an error if C<STORABLE_freeze> tries to return references.
=end original
これらのリソースオブジェクトはプロセス/システム全体で所有されているもので、
何かの「属性」が直列化されているものではないと考えられているので、
オブジェクトの下のリファレンスは直列化した文字列に含まれるべきではありません。
従って、C<STORABLE_attach> を実装しているクラスでは、
C<STORABLE_freeze> メソッドはリファレンスを返すことはできず、
C<STORABLE_freeze> がリファレンスを返そうとすると C<Storable> はエラーを
投げます。
=begin original
All information required to "attach" back to the shared resource object
B<must> be contained B<only> in the C<STORABLE_freeze> return string.
Otherwise, C<STORABLE_freeze> behaves as normal for C<STORABLE_attach>
classes.
=end original
共有リソースオブジェクトに戻すために必要な全ての情報は、
C<STORABLE_freeze> の返り文字列 B<にのみ> 含まれていなければ B<なりません>。
さもなければ、C<STORABLE_freeze> は C<STORABLE_attach> クラスには
通常通りに振る舞います。
=begin original
Because C<STORABLE_attach> is passed the class (rather than an object),
it also returns the object directly, rather than modifying the passed
object.
=end original
C<STORABLE_attach> は(オブジェクトではなく)クラスを渡されるので、
渡されたオブジェクトを修正したものではなくオブジェクトを直接返します。
=begin original
Returned value: object of type C<class>
=end original
返り値: オブジェクトの型 C<class>
=back
=head2 Predicates
(述語)
=begin original
Predicates are not exportable. They must be called by explicitly prefixing
them with the Storable package name.
=end original
述語(Predicates) はエクスポート可能ではありません。
それらは Storable パッケージ名を明示的に前につけて
呼び出されなければなりません。
=over 4
=item C<Storable::last_op_in_netorder>
=begin original
The C<Storable::last_op_in_netorder()> predicate will tell you whether