diff options
author | Yorhel <git@yorhel.nl> | 2021-01-04 14:33:34 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-01-04 14:33:36 +0100 |
commit | b3c79d8c9deada792377a57b5bf4e2c81455004c (patch) | |
tree | 34f85db033ddca3384fad5ce9c7de28b2b251ae4 /lib/VNDB | |
parent | e0fdfb55a21eecae700c969c728b5ea0fef2cf45 (diff) |
refactor: Move & simplify SkinFile into VNDB::Skins
VNDB::Skins now behaves the same way as VNDB::Config - it provides a
single function that returns all the info you'll need.
This removes the tuwf->{skins} global variable, making skin-querying
code independent of the TUWF object, and, again, moving some
library-related functionality out of vndb.pl.
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/Skins.pm | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/VNDB/Skins.pm b/lib/VNDB/Skins.pm new file mode 100644 index 00000000..a0716024 --- /dev/null +++ b/lib/VNDB/Skins.pm @@ -0,0 +1,29 @@ +package VNDB::Skins; + +use v5.26; +use warnings; +use Exporter 'import'; +our @EXPORT = ('skins'); + +my $ROOT = $INC{'VNDB/Skins.pm'} =~ s{/lib/VNDB/Skins\.pm$}{}r; + +my $skins; + +sub skins { + $skins ||= do { +{ map { + my $skin = /\/([^\/]+)\/conf/ ? $1 : die; + my %o; + open my $F, '<:utf8', $_ or die $!; + while(<$F>) { + chomp; + s/\r//g; + s{[\t\s]*//.+$}{}; + next if !/^([a-z0-9]+)[\t\s]+(.+)$/; + $o{$1} = $2; + } + +( $skin, \%o ) + } glob "$ROOT/static/s/*/conf" } }; + $skins; +} + +1; |