MIME::Parser::AbstractFiler - manage file-output of the parser
Ready? Ok... now read ``DESCRIPTION'' below, and everything else should make sense.
Every parser has a single Filer object, which it uses for all parsing. You can get the Filer for a given $parser like this:
$filer = $parser->filer;
At the beginning of each "parse()", the filer's internal state is reset by the parser:
$parser->filer->init_parse;
The parser can then get a path for each entity in the message by handing that entity's header (a MIME::Head) to the filer and having it do the work, like this:
$new_file = $parser->filer->output_path($head);
Since it's nice to be able to clean up after a parse (especially a failed parse), the parser tells the filer when it has actually used a path:
$parser->filer->purgeable($new_file);
Then, if you want to clean up the files which were created for a particular parse (and also any directories that the Filer created), you would do this:
$parser->filer->purge;
In general, though, the only method you have to override is output_path():
$filer->output_path($head);
This method is invoked by MIME::Parser when it wants to put a decoded message body in an output file. The method should return a path to the file to create. Failure is indicated by throwing an exception.
The path returned by "output_path()" should be ``ready for open()'': any necessary parent directories need to exist at that point. These directories can be created by the Filer, if course, and they should be marked as purgeable() if a purge should delete them.
If PATH is not given, the ``purgeable'' list is returned. This may be used for more-sophisticated purging.
As a special case, invoking this method with a PATH that is an arrayref will replace the purgeable list with a copy of the array's contents, so [] may be used to clear the list.
Note that the ``purgeable'' list is cleared when a parser begins a new parse; therefore, if you want to use purge() to do cleanup, you must do so before starting a new parse!
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |