package Games::NES::ROM::Database; =head1 NAME Games::NES::ROM::Database - Known info about existing ROMs =head1 SYNOPSIS use Games::NES::ROM::Database; my $db = Games::NES::ROM->new; my $info = $db->find_by_crc( $crc ); =head1 DESCRIPTION This database holds information about known game images. You can find out which mapper to use, how many PRG and CHR chunks it has, if it is an NTSC or PAL game, among other things. =head1 DATABASE VERSION The database has been synchronized with version 1.40 of the Nestopia emulator. =cut use Moose; use XML::XPath; use XML::Simple; has 'xpath' => ( is => 'ro', isa => 'XML::XPath', default => sub { XML::XPath->new( ioref => \*DATA ); }, lazy => 1, ); =head1 METHODS =head2 new( ) Creates a new instance of the database. =head2 find_by_crc( $crc ) Given a CRC hex string, it will return a hashref of info from the database or undef if it does not exist in the database. =cut sub find_by_crc { my $self = shift; my $crc = uc( shift ); return _nodeset_to_hashref( $self->xpath->find( "database/game[cartridge[\@crc='${crc}']]" ) ); } =head2 find_by_sha1( $sha1 ) Similar to C, but uses an SHA-1 hex string. =cut sub find_by_sha1 { my $self = shift; my $sha1 = uc( shift ); return _nodeset_to_hashref( $self->xpath->find( "database/game[cartridge[\@sha1='${sha1}']]" ) ); } sub _nodeset_to_hashref { my $ns = shift; return undef unless $ns->size; return XML::Simple::XMLin( $ns->shift->toString ); } =head2 find_by_rom( $rom ) Similar to C, but accepts a L-derived object. =cut sub find_by_rom { my ( $self, $rom ) = @_; return $self->find_by_crc( $rom->crc ); } =head1 SEE ALSO =over 4 =item * Games::NES::ROM =item * http://nestopia.sourceforge.net/ =back =head1 AUTHOR Brian Cassidy Ebricas@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright 2007-2010 by Brian Cassidy This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; __DATA__