Hi,

When working with this week challenge for the PerlWeeklyChallenge
<https://perlweeklychallenge.org/>, I noticed this behaviour with TWEAK:

*This does not work:*
  submethod TWEAK {
    $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
)  });
  }

*This works:*
  submethod TWEAK {
    $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
)  });
    return;
  }

It also works with other commands instead of 'return' (like assigning a
value to a variable). From the examples in the documentation, I am not
certain this is the expected behaviour.

Thanks for this extraordinary language,

Joan


P.S: This is the context where the command appears.  Apologies for the
messy-Raku,
------------------------------
use Test;

my $data = '1709363,"Les Miserables Episode 1: The Bishop (broadcast date:
1937-07-23)"
1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)"
1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)"
1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)"
1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)"
1714640,"Les Miserables Episode 6: The Barricade (broadcast date:
1937-08-27)"
1714640,"Les Miserables Episode 7: Conclusion (broadcast date:
1937-09-03)"';

class Movies {

  has $.starttime;
  has $.currenttime;
  has $.filelist;
  has @!show; # ( [ time, show ] )

  submethod TWEAK {
    # miliseconds -> seconds
    $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b
)  });
    return;
  }

  method what-show() {
    my $position =  ( $!currenttime - $!starttime ) % @!show[*;0].sum/1000;
    my ($time, $show);
    for @!show[*;0] -> $show-time {
      $time += $show-time;
      return @!show[$show++;1] if $time > $position;
    }
  }
}

my $mv = Movies.new(
  starttime   => '1606134123',
  currenttime => '1614591276',
  filelist    => $data
);

is $mv.what-show, '"Les Miserables Episode 1: The Bishop (broadcast date:
1937-07-23)"';

Reply via email to