1 | package Convert::UUlib; |
1 | package Convert::UUlib; |
2 | |
2 | |
3 | no warnings; |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
6 | use Carp; |
5 | use Carp; |
7 | |
6 | |
8 | require Exporter; |
7 | require Exporter; |
9 | require DynaLoader; |
8 | require DynaLoader; |
… | |
… | |
48 | our @EXPORT_OK = @_funcs; |
47 | our @EXPORT_OK = @_funcs; |
49 | our %EXPORT_TAGS = (all => [@_consts,@_funcs], constants => \@_consts); |
48 | our %EXPORT_TAGS = (all => [@_consts,@_funcs], constants => \@_consts); |
50 | |
49 | |
51 | bootstrap Convert::UUlib $VERSION; |
50 | bootstrap Convert::UUlib $VERSION; |
52 | |
51 | |
53 | Initialize(); |
52 | # dummy function for compatiiblity with pre-1.7 versions |
54 | |
53 | sub Initialize { } |
55 | # not when < 5.005_6x |
|
|
56 | # END { CleanUp() } |
|
|
57 | |
|
|
58 | for (@_consts) { |
|
|
59 | my $constant = constant($_); |
|
|
60 | no strict 'refs'; |
|
|
61 | *$_ = sub () { $constant }; |
|
|
62 | } |
|
|
63 | |
54 | |
64 | # action code -> string mapping |
55 | # action code -> string mapping |
65 | sub straction($) { |
56 | sub straction($) { |
66 | return 'copying' if $_[0] == &ACT_COPYING; |
57 | return 'copying' if $_[0] == &ACT_COPYING; |
67 | return 'decoding' if $_[0] == &ACT_DECODING; |
58 | return 'decoding' if $_[0] == &ACT_DECODING; |
… | |
… | |
105 | use Convert::UUlib ':all'; |
96 | use Convert::UUlib ':all'; |
106 | |
97 | |
107 | # read all the files named on the commandline and decode them |
98 | # read all the files named on the commandline and decode them |
108 | # into the CURRENT directory. See below for a longer example. |
99 | # into the CURRENT directory. See below for a longer example. |
109 | LoadFile $_ for @ARGV; |
100 | LoadFile $_ for @ARGV; |
|
|
101 | |
110 | for my $uu (GetFileList) { |
102 | for my $uu (GetFileList) { |
111 | if ($uu->state & FILE_OK) { |
103 | if ($uu->state & FILE_OK) { |
112 | $uu->decode; |
104 | $uu->decode; |
113 | print $uu->filename, "\n"; |
105 | print $uu->filename, "\n"; |
114 | } |
106 | } |
… | |
… | |
216 | On my machine, a fairly complete decode with DBI backend needs about 10MB |
208 | On my machine, a fairly complete decode with DBI backend needs about 10MB |
217 | RSS to decode 20000 files. |
209 | RSS to decode 20000 files. |
218 | |
210 | |
219 | =over |
211 | =over |
220 | |
212 | |
221 | =item Initialize |
|
|
222 | |
|
|
223 | Not normally necessary, (re-)initializes the library. |
|
|
224 | |
|
|
225 | =item CleanUp |
213 | =item CleanUp |
226 | |
214 | |
227 | Not normally necessary, could be called at the end to release memory |
215 | Release memory, file items and clean up files. Should be called after a |
228 | before starting a new decoding round. |
216 | decoidng run, if you want to start a new one. |
229 | |
217 | |
230 | =back |
218 | =back |
231 | |
219 | |
232 | =head2 Setting and querying options |
220 | =head2 Setting and querying options |
233 | |
221 | |
… | |
… | |
448 | |
436 | |
449 | =back |
437 | =back |
450 | |
438 | |
451 | =head1 LARGE EXAMPLE DECODER |
439 | =head1 LARGE EXAMPLE DECODER |
452 | |
440 | |
|
|
441 | The general workflow for decoding is like this: |
|
|
442 | |
|
|
443 | =over |
|
|
444 | |
|
|
445 | =item 1. Configure options with C<SetOption> or C<SetXXXCallback>. |
|
|
446 | |
|
|
447 | =item 2. Load all source files with C<LoadFile>. |
|
|
448 | |
|
|
449 | =item 3. Optionally C<Smerge>. |
|
|
450 | |
|
|
451 | =item 4. Iterate over all C<GetFileList> items (i.e. result files). |
|
|
452 | |
|
|
453 | =item 5. C<CleanUp> to delete files and free items. |
|
|
454 | |
|
|
455 | =back |
|
|
456 | |
453 | This is the file C<example-decoder> from the distribution, put here |
457 | What follows is the file C<example-decoder> from the distribution that |
454 | instead of more thorough documentation. |
458 | illustrates the above worklfow in a non-trivial example. |
455 | |
459 | |
456 | #!/usr/bin/perl |
460 | #!/usr/bin/perl |
457 | |
461 | |
458 | # decode all the files in the directory uusrc/ and copy |
462 | # decode all the files in the directory uusrc/ and copy |
459 | # the resulting files to uudst/ |
463 | # the resulting files to uudst/ |