| 1 | package BioSAILs::Utils::CacheUtils; | ||
| 2 | |||
| 3 | use Moose::Role; | ||
| 4 | use namespace::autoclean; | ||
| 5 | |||
| 6 | with 'BioSAILs::Utils::LoadConfigs'; | ||
| 7 | |||
| 8 | use YAML; | ||
| 9 | |||
| 10 | =head3 comment_char | ||
| 11 | |||
| 12 | Default comment char is '#'. | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | has 'comment_char' => ( | ||
| 17 | is => 'rw', | ||
| 18 | isa => 'Str', | ||
| 19 | default => '#', | ||
| 20 | ); | ||
| 21 | |||
| 22 | sub print_cmd_line_opts { | ||
| 23 | my $self = shift; | ||
| 24 | |||
| 25 | my $now = DateTime->now(); | ||
| 26 | my $cmd_line_opts = ""; | ||
| 27 | |||
| 28 | $cmd_line_opts .= "$self->{comment_char}\n"; | ||
| 29 | $cmd_line_opts .= "$self->{comment_char} Generated at: $now\n"; | ||
| 30 | $cmd_line_opts .= | ||
| 31 | "$self->{comment_char} " | ||
| 32 | . "This file was generated with the following options\n"; | ||
| 33 | |||
| 34 | $cmd_line_opts .= "$self->{comment_char}\t" . $ARGV[0] . "\n" if $ARGV[0]; | ||
| 35 | for ( my $x = 1 ; $x <= $#ARGV ; $x++ ) { | ||
| 36 | next unless $ARGV[$x]; | ||
| 37 | $cmd_line_opts .= "$self->{comment_char}\t$ARGV[$x]"; | ||
| 38 | if ( $x == $#ARGV ) { | ||
| 39 | $cmd_line_opts .= "\n"; | ||
| 40 | } | ||
| 41 | else { | ||
| 42 | $cmd_line_opts .= "\t\\\n"; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | $cmd_line_opts .= "$self->{comment_char}\n\n"; | ||
| 47 | |||
| 48 | return $cmd_line_opts; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub print_config_data { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | return "" unless scalar keys %{ $self->_merged_config_data }; | ||
| 55 | my $config_str = Dump( $self->_merged_config_data ); | ||
| 56 | my @split = split( "\n", $config_str ); | ||
| 57 | my $config_opts = ""; | ||
| 58 | |||
| 59 | $config_opts .= "$self->{comment_char}\n"; | ||
| 60 | $config_opts .= "$self->{comment_char} " . "Invoked with configuration:\n"; | ||
| 61 | |||
| 62 | map { $config_opts .= "# " . $_ } @split; | ||
| 63 | |||
| 64 | return $config_opts; | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; |