comparison lib/CPT/Writer.pm @ 1:97ef96676b48 draft

planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author cpt
date Mon, 05 Jun 2023 02:51:26 +0000
parents
children
comparison
equal deleted inserted replaced
0:b18e8268bf4e 1:97ef96676b48
1 package CPT::Writer;
2 use Moose::Role;
3 use strict;
4 use warnings;
5 use autodie;
6
7 requires 'process';
8 requires 'suffix';
9
10 # One or the other of these will be set. *ought* to be in accordance w/ galaxy_override
11 has 'OutputFilesClass' => ( is => 'rw' );
12
13 # This parameter specifies that we should behave according to galaxy_override spec.
14 has 'galaxy_override' => ( is => 'rw', isa => 'Bool' );
15 has 'title' => ( is => 'rw', isa => 'Str' );
16 has 'author' => ( is => 'rw', isa => 'Str' );
17 has 'data' => ( is => 'rw' );
18 has 'processed_data' => ( is => 'rw' );
19 has 'processing_complete' => ( is => 'rw', isa => 'Bool' );
20 # What file names were generated during the writing process
21 has 'used_filenames' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] });
22 # An optional, hinted at name. Otherwise we'll generate one.
23 has 'name' => ( is => 'rw', isa => 'Str' );
24
25 sub write {
26 my ($self) = @_;
27 if ( $self->processing_complete ) {
28 $self->OutputFilesClass->extension( $self->suffix() );
29 my $next_output_file = $self->OutputFilesClass->get_next_file();
30 # Store the name of the file we used
31 push(@{$self->used_filenames()}, $next_output_file);
32 # Write data out
33 open(my $outfile, '>', $next_output_file );
34 print $outfile $self->processed_data; # given that processed_data is a string...
35 close($outfile);
36 }
37 else {
38 warn "Write called but processing was not marked as complete. Not writing";
39 }
40 }
41
42 sub get_name {
43 my ($self) = @_;
44 #return $self->OutputFilesClass->get_next_file();
45 return $self->OutputFilesClass->_get_filename();
46 }
47
48 sub process_data {
49 my ($self) = @_;
50 if (!defined $self->data ) {
51 #confess "No data to process.";
52 }
53 $self->process();
54 }
55
56 no Moose::Role;
57 1;
58
59 __END__
60
61 =pod
62
63 =encoding UTF-8
64
65 =head1 NAME
66
67 CPT::Writer
68
69 =head1 VERSION
70
71 version 1.99.4
72
73 =head1 AUTHOR
74
75 Eric Rasche <rasche.eric@yandex.ru>
76
77 =head1 COPYRIGHT AND LICENSE
78
79 This software is Copyright (c) 2014 by Eric Rasche.
80
81 This is free software, licensed under:
82
83 The GNU General Public License, Version 3, June 2007
84
85 =cut