10 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
13 @EXPORT = qw(&parse_masters %oceans %commods
14 &parse_pctb_commodmap %pctb_commodmap @pctb_commodmap);
20 our %oceans; # eg $oceans{'Midnight'}{'Ruby'}{'Eta Island'}= $sources
21 our %commods; # eg $commods{'Fine black cloth'}= $sources;
23 # 's' = Special Circumstances; 'l' = local ; B = with Bleach
25 our (%pctb_commodmap,@pctb_commodmap);
27 my %colours; # eg $colours{'c'}{'black'}= $sources
28 my @rawcm; # eg $rawcm[0]='fine rum'; $rawcm[1]='fine %c cloth'
30 sub parse_master_master1 ($$) {
32 my $mm= new IO::File $mmfn, 'r' or die "$mmfn $!";
40 @ctx= (sub { $colours{$colourkind}{lc $_} .= $src; });
41 } elsif (m/^commods$/) {
42 @ctx= (sub { push @rawcm, lc $_; });
43 } elsif (m/^ocean (\w+)$/) {
46 $ocean or die; # ref to $ocean needed to work
50 $oceans{$ocean}{$arch}{$_} .= $src;
54 my $indent= length $&;
55 die "wrong indent $indent" unless defined $ctx[$indent-1];
56 &{ $ctx[$indent-1] }();
61 $mm->error and die $!;
64 #print Dumper(\%oceans);
65 #print Dumper(\@rawcm);
72 if ($s !~ m/\%(\w+)/) { $commods{ucfirst $s} .= $ss; return; }
73 die "unknown $&" unless defined $colours{$1};
74 foreach my $c (keys %{ $colours{$1} }) {
75 &$ca($`.$c.$', $ss .'%'. $colours{$1}{$c});
78 foreach (@rawcm) { &$ca($_,$src); }
81 sub parse_masters () {
82 parse_master_master1('master-master.txt','s');
85 sub parse_pctb_commodmap () {
86 undef %pctb_commodmap;
87 foreach my $commod (keys %commods) { $commods{$commod} =~ s/b//; }
89 my $c= new IO::File '_commodmap.tsv' or die $!;
90 if (!$c) { $!==&ENOENT or die $!; return 0; }
93 m/^(\S.*\S)\t(\d+)\n$/ or die "$_";
94 die if defined $pctb_commodmap{$1}; $pctb_commodmap{$1}= $2;
95 die if defined $pctb_commodmap[$2]; $pctb_commodmap[$2]= $1;