@@ -7,6 +7,7 @@ use Data::Walk;
77use Data::Dumper;
88use File::Path qw( make_path remove_tree) ;
99use Try::Tiny;
10+ use Path::Tiny;
1011
1112with ' BioX::Workflow::Command::Utils::Files::TrackChanges' ;
1213use BioX::Workflow::Command::Utils::Traits qw( ArrayRefOfStrs) ;
@@ -582,15 +583,6 @@ sub template_process {
582583
583584 $self -> process_obj-> { $self -> rule_name }-> {meta } =
584585 $self -> write_rule_meta(' before_meta' );
585-
586- # return unless $self->use_timestamps;
587- # if ( $self->local_attr->{_modified} ) {
588- # $self->app_log->info(
589- # 'One or more files were modified or are not logged for this rule');
590- # }
591- # else {
592- # $self->app_log->info('Zero files were modified for this rule');
593- # }
594586}
595587
596588sub use_iterables {
@@ -632,12 +624,14 @@ sub check_iterables {
632624 # First check the global for any lists
633625 my $use_iters = $self -> use_iterables;
634626
635- if ( ! $use_iters ) {
627+ $self -> walk_indir_outdir($use_iters );
628+
629+ if ( !$use_iters ) {
636630 $texts = $self -> in_template_process( $sample , $texts );
637631 return $texts ;
638632 }
639633
640- my $all = $use_iters -> [0];
634+ my $all = $use_iters -> [0];
641635 my $elem = $use_iters -> [1];
642636
643637 # #TODO This should be a separate function
@@ -709,31 +703,81 @@ sub get_keys {
709703 $self -> rule_keys( \@global_keys );
710704}
711705
712- sub walk_attr {
713- my $self = shift ;
706+ # #TODO Clean this up and merge with the other walk_iterables
707+ sub walk_indir_outdir {
708+ my $self = shift ;
709+ my $use_iters = shift ;
714710
715711 my $attr = dclone( $self -> local_attr );
716712 $self -> check_indir_outdir($attr );
717713
718- $DB::single = 2;
714+ my $dummy_sample = $self -> dummy_sample;
715+ $attr -> sample($dummy_sample );
716+ my $text = $attr -> interpol_directive( $attr -> outdir );
719717
720- $attr -> walk_process_data( $self -> rule_keys );
718+ if ( !$use_iters ) {
719+ foreach my $sample ( $attr -> all_samples ) {
720+ my $new_text = $text ;
721+ $new_text =~ s / $dummy_sample/ $sample / g ;
722+ $new_text = path($new_text )-> absolute if $attr -> coerce_abs_dir;
723+ $new_text = path($new_text ) if !$attr -> coerce_abs_dir;
724+ $self -> decide_create_outdir( $attr , $new_text );
725+ }
726+ return ;
727+ }
728+
729+ my $all = $use_iters -> [0];
730+ my $elem = $use_iters -> [1];
731+
732+ # #TODO This should be a separate function
733+ my $dummy_iter = $self -> dummy_iterable;
734+ $attr -> $elem ($dummy_iter );
721735
722- if ( $attr -> create_outdir && !$attr -> outdir-> is_dir ) {
736+ foreach my $chunk ( $self -> local_attr-> $all ) {
737+ my $new_text = $text ;
738+ $new_text =~ s / $dummy_iter/ $chunk / g ;
739+ $new_text = path($new_text )-> absolute if $attr -> coerce_abs_dir;
740+ $new_text = path($new_text ) if !$attr -> coerce_abs_dir;
741+ $self -> decide_create_outdir( $attr , $new_text );
742+ }
743+ }
744+
745+ sub decide_create_outdir {
746+ my $self = shift ;
747+ my $attr = shift ;
748+ my $dir = shift ;
749+
750+ if ( $attr -> create_outdir ) {
723751
724752 try {
725- $attr -> outdir -> mkpath;
753+ $dir -> mkpath;
726754 }
727755 catch {
728756 $self -> app_log-> fatal( " We were not able to make the directory.\n\t "
729757 . $attr -> outdir
730758 . " \n\t Error: $! " );
731759 };
732760 }
761+ }
762+
763+ sub walk_attr {
764+ my $self = shift ;
765+
766+ my $attr = dclone( $self -> local_attr );
767+ $self -> check_indir_outdir($attr );
768+
769+ $DB::single = 2;
770+
771+ $attr -> walk_process_data( $self -> rule_keys );
733772
734773 return $attr ;
735774}
736775
776+ sub make_outdirs {
777+ my $self = shift ;
778+
779+ }
780+
737781sub eval_process {
738782 my $self = shift ;
739783
0 commit comments