Mercurial > repos > cpt > cpt_psm_recombine
annotate lib/CPT/Writer/Archive.pm @ 2:d09346afadfa draft default tip
planemo upload commit f33bdf952d796c5d7a240b132af3c4cbd102decc
| author | cpt | 
|---|---|
| date | Fri, 05 Jan 2024 05:56:18 +0000 | 
| parents | 97ef96676b48 | 
| children | 
| rev | line source | 
|---|---|
| 
1
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
1 package CPT::Writer::Archive; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
2 no warnings; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
3 use Moose; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
4 use Archive::Any::Create; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
5 use File::Copy qw/move/; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
6 with 'CPT::Writer'; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
7 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
8 has format => ( | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
9 is => 'ro', | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
10 isa => 'Str', | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
11 default => sub { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
12 'tar.gz', | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
13 }, | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
14 ); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
15 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
16 sub process { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
17 my ($self) = @_; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
18 # Should be a Archive::Any::Create object | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
19 if(ref $self->data() ne 'Archive::Any::Create'){ | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
20 warn 'Tool author sent non Archive::Any::Create data to the writer'; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
21 }else{ | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
22 $self->processed_data( $self->data() ); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
23 $self->processing_complete(1); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
24 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
25 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
26 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
27 sub write { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
28 my ($self) = @_; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
29 if ( $self->processing_complete ) { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
30 # Force the extension to that of the specified format | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
31 $self->OutputFilesClass->extension( $self->format() ); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
32 # Get a filename | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
33 my $next_output_file = $self->OutputFilesClass->get_next_file(); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
34 # And get another filename with extension tacked on so we KNOW it'll behave correctly. | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
35 my $next_output_file_with_extension = $self->OutputFilesClass->get_next_file() . '.' . $self->format(); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
36 # Store the name of the file we used | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
37 push(@{$self->used_filenames()}, $next_output_file); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
38 # Write data out | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
39 $self->processed_data->write_file($next_output_file_with_extension); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
40 # If it has been written somewhere other than where we want, | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
41 # then we need to move it. | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
42 if($next_output_file ne $next_output_file_with_extension){ | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
43 move($next_output_file_with_extension, $next_output_file); | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
44 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
45 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
46 else { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
47 warn | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
48 "Write called but processing was not marked as complete. Not writing"; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
49 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
50 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
51 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
52 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
53 sub suffix { | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
54 return 'csv'; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
55 } | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
56 no Moose; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
57 1; | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
58 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
59 __END__ | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
60 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
61 =pod | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
62 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
63 =encoding UTF-8 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
64 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
65 =head1 NAME | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
66 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
67 CPT::Writer::Archive | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
68 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
69 =head1 VERSION | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
70 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
71 version 1.99.4 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
72 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
73 =head1 AUTHOR | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
74 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
75 Eric Rasche <rasche.eric@yandex.ru> | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
76 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
77 =head1 COPYRIGHT AND LICENSE | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
78 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
79 This software is Copyright (c) 2014 by Eric Rasche. | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
80 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
81 This is free software, licensed under: | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
82 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
83 The GNU General Public License, Version 3, June 2007 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
84 | 
| 
 
97ef96676b48
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
 
cpt 
parents:  
diff
changeset
 | 
85 =cut | 
