storable.pm

来自「AI::Categorizer is a framework for autom」· PM 代码 · 共 73 行

PM
73
字号
package AI::Categorizer::Storable;use strict;use Storable;use File::Spec ();use File::Path ();sub save_state {  my ($self, $path) = @_;  if (-e $path) {    File::Path::rmtree($path) or die "Couldn't overwrite $path: $!";  }  mkdir($path, 0777) or die "Can't create $path: $!";  Storable::nstore($self, File::Spec->catfile($path, 'self'));}sub restore_state {  my ($package, $path) = @_;  return Storable::retrieve(File::Spec->catfile($path, 'self'));}1;__END__=head1 NAMEAI::Categorizer::Storable - Saving and Restoring State=head1 SYNOPSIS  $object->save_state($path);  ... time passes ...  $object = Class->restore_state($path);  =head1 DESCRIPTIONThis class implements methods for storing the state of an object to afile and restoring from that file later.  In C<AI::Categorizer> it isgenerally used in order to let data persist across multipleinvocations of a program.=head1 METHODS=over 4=item save_state($path)This object method saves the object to disk for later use.  TheC<$path> argument indicates the place on disk where the object shouldbe saved.=item restore_state($path)This class method reads the file specified by C<$path> and returns theobject that was previously stored there using C<save_state()>.=head1 AUTHORKen Williams, ken@mathforum.org=head1 COPYRIGHTCopyright 2000-2003 Ken Williams.  All rights reserved.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=head1 SEE ALSOAI::Categorizer(3), Storable(3)=cut

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?