common: global Data() to parse perl code includes
[sheet.git] / common.inc.plp
index 71c5c1379f29aeb82d6d1211ec53dff69740d2cf..39865bdb55f2ca961da6d7f0ebcaecbc760aab9a 100644 (file)
@@ -99,6 +99,20 @@ sub checkmodified {
        $header{'Last-Modified'} = time2str($lastmod);
 }
 
+sub Data {
+       my ($filename) = @_;
+       my @data = eval {
+               do "$filename.inc.pl";
+       };
+       if ($! or $@ or !@data or !$data[0]) {
+               die ['Table data not found', $@ || $!];
+       }
+       if (@data == 1 and ref $data[0] eq 'HASH' and not %{$data[0]}) {
+               die ['Table data missing'];
+       }
+       return wantarray ? @data : $data[0]; # list compatibility like do does
+}
+
 sub Html {
        my ($meta) = @_;