view release on metacpan or search on metacpan
bin/bommer.pl view on Meta::CPAN
use strict;
use warnings;
use warnings qw(FATAL utf8); # Fatalize encoding glitches.
use File::BOM::Utils;
use Getopt::Long;
use Pod::Usage;
bin/bommer.pl view on Meta::CPAN
'output_file=s',
) )
{
pod2usage(1) if ($option{'help'});
exit File::BOM::Utils -> new(%option) -> run;
}
else
{
pod2usage(2);
}
bin/bommer.pl view on Meta::CPAN
=pod
=head1 NAME
bommer.pl - Check, Add and Remove BOMs
=head1 SYNOPSIS
bommer.pl [options]
bin/bommer.pl view on Meta::CPAN
=over 4
=item o add
Add the BOM named with the bom_name option to input_file.
Write the result to output_file.
=item o remove
Remove the BOM from the input_file. Write the result to output_file.
=item o test
Report the BOM status of input_file.
=back
Default: ''.
This option is mandatory.
=item -bom_name => $string
Specify which BOM to add to C<input_file>.
This option is mandatory if the C<action> is C<add>.
Values (always upper-case):
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/BOM.pm view on Meta::CPAN
package File::BOM;
=head1 NAME
File::BOM - Utilities for handling Byte Order Marks
=head1 SYNOPSIS
use File::BOM qw( :all )
=head2 high-level functions
# read a file with encoding from the BOM:
open_bom(FH, $file)
open_bom(FH, $file, ':utf8') # the same but with a default encoding
# get encoding too
$encoding = open_bom(FH, $file, ':utf8');
# open a potentially unseekable file:
($encoding, $spillage) = open_bom(FH, $file, ':utf8');
# change encoding of an open handle according to BOM
$encoding = defuse(*HANDLE);
($encoding, $spillage) = defuse(*HANDLE);
# Decode a string according to leading BOM:
$unicode = decode_from_bom($string_with_bom);
# Decode a string and get the encoding:
($unicode, $encoding) = decode_from_bom($string_with_bom)
=head2 PerlIO::via interface
# Read the Right Thing from a unicode file with BOM:
open(HANDLE, '<:via(File::BOM)', $filename)
# Writing little-endian UTF-16 file with BOM:
open(HANDLE, '>:encoding(UTF-16LE):via(File::BOM)', $filename)
=head2 lower-level functions
# read BOM encoding from a filehandle:
$encoding = get_encoding_from_filehandle(FH)
# Get encoding even if FH is unseekable:
($encoding, $spillage) = get_encoding_from_filehandle(FH);
# Get encoding from a known unseekable handle:
($encdoing, $spillage) = get_encoding_from_stream(FH);
# get encoding and BOM length from BOM at start of string:
($encoding, $offset) = get_encoding_from_bom($string);
=head2 variables
# print a BOM for a known encoding
print FH $enc2bom{$encoding};
# get an encoding from a known BOM
$enc = $bom2enc{$bom}
=head1 DESCRIPTION
This module provides functions for handling unicode byte order marks, which are
to be found at the beginning of some files and streams.
For details about what a byte order mark is, see
L<http://www.unicode.org/unicode/faq/utf_bom.html#BOM>
The intention of File::BOM is for files with BOMs to be readable as seamlessly
as possible, regardless of the encoding used. To that end, several different
interfaces are available, as shown in the synopsis above.
=cut
lib/File/BOM.pm view on Meta::CPAN
=head2 %bom2enc
Maps Byte Order marks to their encodings.
The keys of this hash are strings which represent the BOMs, the values are their
encodings, in a format which is understood by L<Encode>
The encodings represented in this hash are: UTF-8, UTF-16BE, UTF-16LE,
UTF-32BE and UTF-32LE
=head2 %enc2bom
A reverse-lookup hash for bom2enc, with a few aliases used in L<Encode>, namely utf8, iso-10646-1 and UCS-2.
Note that UTF-16, UTF-32 and UCS-4 are not included in this hash. Mainly
because Encode::encode automatically puts BOMs on output. See L<Encode::Unicode>
=cut
our(%bom2enc, %enc2bom, $MAX_BOM_LENGTH, $bom_re);
# length in bytes of the longest BOM
$MAX_BOM_LENGTH = 4;
Readonly %bom2enc => (
map { encode($_, "\x{feff}") => $_ } qw(
UTF-8
UTF-16BE
lib/File/BOM.pm view on Meta::CPAN
{
local $" = '|';
my @bombs = sort { length $b <=> length $a } keys %bom2enc;
Readonly $MAX_BOM_LENGTH => length $bombs[0];
Readonly $bom_re => qr/^(@bombs)/o;
}
=head1 FUNCTIONS
lib/File/BOM.pm view on Meta::CPAN
$encoding = open_bom(HANDLE, $filename, $default_mode)
($encoding, $spill) = open_bom(HANDLE, $filename, $default_mode)
opens HANDLE for reading on $filename, setting the mode to the appropriate
encoding for the BOM stored in the file.
On failure, a fatal error is raised, see the DIAGNOSTICS section for details on
how to catch these. This is in order to allow the return value(s) to be used for
other purposes.
If the file doesn't contain a BOM, $default_mode is used instead. Hence:
open_bom(FH, 'my_file.txt', ':utf8')
Opens my_file.txt for reading in an appropriate encoding found from the BOM in
that file, or as a UTF-8 file if none is found.
In the absence of a $default_mode argument, the following 2 calls should be equivalent:
open_bom(FH, 'no_bom.txt');
lib/File/BOM.pm view on Meta::CPAN
# create filehandle on the fly
$enc = open_bom(my $fh, $filename, ':utf8');
$line = <$fh>;
The filehandle will be cued up to read after the BOM. Unseekable files (e.g.
fifos) will cause croaking, unless called in list context to catch spillage
from the handle. Any spillage will be automatically decoded from the encoding,
if found.
e.g.
lib/File/BOM.pm view on Meta::CPAN
$enc = defuse(FH);
($enc, $spill) = defuse(FH);
FH should be a filehandle opened for reading, it will have the relevant encoding
layer pushed onto it be binmode if a BOM is found. Spillage should be Unicode,
not bytes.
Any uncaptured spillage will be silently lost. If the handle is unseekable, use
list context to avoid data loss.
If no BOM is found, the mode will be unaffected.
=cut
sub defuse (*) {
my $fh = qualify_to_ref(shift, caller);
lib/File/BOM.pm view on Meta::CPAN
$unicode_string = decode_from_bom($string, $default, $check)
($unicode_string, $encoding) = decode_from_bom($string, $default, $check)
Reads a BOM from the beginning of $string, decodes $string (minus the BOM) and
returns it to you as a perl unicode string.
if $string doesn't have a BOM, $default is used instead.
$check, if supplied, is passed to Encode::decode as the third argument.
If there's no BOM and no default, the original string is returned and encoding
is ''.
See L<Encode>
=cut
lib/File/BOM.pm view on Meta::CPAN
($encoding, $spillage) = get_encoding_from_filehandle(HANDLE)
Returns the encoding found in the given filehandle.
The handle should be opened in a non-unicode way (e.g. mode '<:bytes') so that
the BOM can be read in its natural state.
After calling, the handle will be set to read at a point after the BOM (or at
the beginning of the file if no BOM was found)
If called in scalar context, unseekable handles cause a croak().
If called in list context, unseekable handles will be read byte-by-byte and any
spillage will be returned. See get_encoding_from_stream()
lib/File/BOM.pm view on Meta::CPAN
=head2 get_encoding_from_stream
($encoding, $spillage) = get_encoding_from_stream(*FH);
Read a BOM from an unrewindable source. This means reading the stream one byte
at a time until either a BOM is found or every possible BOM is ruled out. Any
non-BOM bytes read from the handle will be returned in $spillage.
If a BOM is found and the spillage contains a partial character (judging by the
expected character width for the encoding) more bytes will be read from the
handle to ensure that a complete character is returned.
Spillage is always in bytes, not characters.
lib/File/BOM.pm view on Meta::CPAN
_get_encoding_unseekable($fh);
}
# internal:
#
# Return encoding and seek to position after BOM
sub _get_encoding_seekable (*) {
my $fh = shift;
# This doesn't work on all platforms:
# defined(read($fh, my $bom, $MAX_BOM_LENGTH))
# or croak "Couldn't read from handle: $!";
my $bom = eval { _safe_read($fh, $MAX_BOM_LENGTH) };
croak "Couldn't read from handle: $@" if $@;
my($enc, $off) = get_encoding_from_bom($bom);
seek($fh, $off, SEEK_SET) or croak "Couldn't reset read position: $!";
lib/File/BOM.pm view on Meta::CPAN
return $enc;
}
# internal:
#
# Return encoding and non-BOM overspill
sub _get_encoding_unseekable (*) {
my $fh = shift;
my $so_far = '';
for my $c (1 .. $MAX_BOM_LENGTH) {
# defined(read($fh, my $byte, 1)) or croak "Couldn't read byte: $!";
my $byte = eval { _safe_read($fh, 1) };
croak "Couldn't read byte: $@" if $@;
$so_far .= $byte;
# find matching BOMs
my @possible = grep { $so_far eq substr($_, 0, $c) } keys %bom2enc;
if (@possible == 1 and my $enc = $bom2enc{$so_far}) {
# There's only one match, this must be it
return ($enc, '');
lib/File/BOM.pm view on Meta::CPAN
$spill .= $extra;
return ($enc, $spill);
}
else {
# no BOM
return ('', $so_far . $spill);
}
}
}
}
lib/File/BOM.pm view on Meta::CPAN
=head2 get_encoding_from_bom
($encoding, $offset) = get_encoding_from_bom($string)
Returns the encoding and length in bytes of the BOM in $string.
If there is no BOM, an empty string is returned and $offset is zero.
To get the data from the string, the following should work:
use Encode;
lib/File/BOM.pm view on Meta::CPAN
}
}
=head1 PerlIO::via interface
File::BOM can be used as a PerlIO::via interface.
open(HANDLE, '<:via(File::BOM)', 'my_file.txt');
open(HANDLE, '>:encoding(UTF-16LE):via(File::BOM)', 'out_file.txt');
print "foo\n"; # BOM is written to file here
This method is less prone to errors on non-seekable files as spillage is
incorporated into an internal buffer, but it doesn't give you any information
about the encoding being used, or indeed whether or not a BOM
was present.
There are a few known problems with this interface, especially surrounding
seek() and tell(), please see the BUGS section for more details about this.
=head2 Reading
The via(File::BOM) layer must be added before the handle is read from, otherwise
any BOM will be missed. If there is no BOM, no decoding will be done.
Because of a limitation in PerlIO::via, read() always works on bytes, not characters. BOM decoding will still be done but output will be bytes of UTF-8.
open(BOM, '<:via(File::BOM)', $file);
$bytes_read = read(BOM, $buffer, $length);
$unicode = decode('UTF-8', $buffer, Encode::FB_QUIET);
# Now $unicode is valid unicode and $buffer contains any left-over bytes
=head2 Writing
Add the via(File::BOM) layer on top of a unicode encoding layer to print a BOM
at the start of the output file. This needs to be done before any data is
written. The BOM is written as part of the first print command on the handle, so
if you don't print anything to the handle, you won't get a BOM.
There is a "Wide character in print" warning generated when the via(File::BOM)
layer doesn't receive utf8 on writing. This glitch was resolved in perl version
5.8.7, but if your perl version is older than that, you'll need to make sure
that the via(File::BOM) layer receives utf8 like this:
# This works OK
open(FH, '>:encoding(UTF-16LE):via(File::BOM):utf8', $filename)
# This generates warnings with older perls
open(FH, '>:encoding(UTF-16LE):via(File::BOM)', $filename)
=head2 Seeking
Seeking with SEEK_SET results in an offset equal to the length of any detected
BOM being applied to the position parameter. Thus:
# Seek to end of BOM (not start of file!)
seek(FILE_BOM_HANDLE, 0, SEEK_SET)
=head2 Telling
In order to work correctly with seek(), tell() also returns a postion adjusted
by the length of the BOM.
=cut
sub PUSHED { bless({offset => 0}, $_[0]) || -1 }
lib/File/BOM.pm view on Meta::CPAN
=item * L<Encode>
=item * L<Encode::Unicode>
=item * L<http://www.unicode.org/unicode/faq/utf_bom.html#BOM>
=back
=head1 DIAGNOSTICS
lib/File/BOM.pm view on Meta::CPAN
_get_encoding_seekable() couldn't read the handle. This function is called from
get_encoding_from_filehandle(), defuse() and open_bom()
=item * Couldn't reset read position: $!
_get_encoding_seekable couldn't seek to the position after the BOM.
=item * Couldn't read byte: $!
get_encoding_from_stream couldn't read from the handle. This function is called
from get_encoding_from_filehandle() and open_bom() when the handle or file is
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/Copy/ppport.h view on Meta::CPAN
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
lib/File/Copy/ppport.h view on Meta::CPAN
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
package File::Find::Rule::BOM;
use base qw(File::Find::Rule);
use strict;
use warnings;
use String::BOM qw(file_has_bom);
our $VERSION = 0.03;
# Detect BOM.
sub File::Find::Rule::bom {
my $file_find_rule = shift;
return _bom($file_find_rule);
}
# Detect UTF-8 BOM.
sub File::Find::Rule::bom_utf8 {
my $file_find_rule = shift;
return _bom($file_find_rule, 'UTF-8');
}
# Detect UTF-16 BOM.
sub File::Find::Rule::bom_utf16 {
my $file_find_rule = shift;
return _bom($file_find_rule, 'UTF-16');
}
# Detect UTF-32 BOM.
sub File::Find::Rule::bom_utf32 {
my $file_find_rule = shift;
return _bom($file_find_rule, 'UTF-32');
}
=encoding utf8
=head1 NAME
File::Find::Rule::BOM - Common rules for searching for BOM in files.
=head1 SYNOPSIS
use File::Find::Rule;
use File::Find::Rule::BOM;
my @files = File::Find::Rule->bom->in($dir);
my @files = File::Find::Rule->bom_utf8->in($dir);
my @files = File::Find::Rule->bom_utf16->in($dir);
my @files = File::Find::Rule->bom_utf32->in($dir);
=head1 DESCRIPTION
This Perl module contains File::Find::Rule rules for detecting Byte Order Mark
in files.
BOM (Byte Order Mark) is a particular usage of the special Unicode character,
U+FEFF BYTE ORDER MARK, whose appearance as a magic number at the start of a
text stream can signal several things to a program reading the text.
See L<Byte order mark on Wikipedia|https://en.wikipedia.org/wiki/Byte order mark>.
=head2 C<bom>
my @files = File::Find::Rule->bom->in($dir);
The C<bom()> rule detect files with BOM.
=head2 C<bom_utf8>
my @files = File::Find::Rule->bom_utf8->in($dir);
The C<bom_utf8()> rule detect files with UTf-8 BOM.
=head2 C<bom_utf16>
my @files = File::Find::Rule->bom_utf16->in($dir);
The C<bom_utf16()> rule detect files with UTF-16 BOM.
=head2 C<bom_utf32>
my @files = File::Find::Rule->bom_utf32->in($dir);
The C<bom_utf32()> rule detect files with UTF-32 BOM.
=head1 EXAMPLE1
use strict;
use warnings;
use File::Find::Rule;
use File::Find::Rule::BOM;
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 dir\n";
exit 1;
}
my $dir = $ARGV[0];
# Print all files with BOM in directory.
foreach my $file (File::Find::Rule->bom->in($dir)) {
print "$file\n";
}
# Output like:
use strict;
use warnings;
use File::Find::Rule;
use File::Find::Rule::BOM;
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 dir\n";
exit 1;
}
my $dir = $ARGV[0];
# Print all files with UTF-8 BOM in directory.
foreach my $file (File::Find::Rule->bom_utf8->in($dir)) {
print "$file\n";
}
# Output like:
use strict;
use warnings;
use File::Find::Rule;
use File::Find::Rule::BOM;
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 dir\n";
exit 1;
}
my $dir = $ARGV[0];
# Print all files with UTF-16 BOM in directory.
foreach my $file (File::Find::Rule->bom_utf16->in($dir)) {
print "$file\n";
}
# Output like:
use strict;
use warnings;
use File::Find::Rule;
use File::Find::Rule::BOM;
# Arguments.
if (@ARGV < 1) {
print STDERR "Usage: $0 dir\n";
exit 1;
}
my $dir = $ARGV[0];
# Print all files with UTF-32 BOM in directory.
foreach my $file (File::Find::Rule->bom_utf32->in($dir)) {
print "$file\n";
}
# Output like:
# Usage: qr{[\w\/]+} dir
=head1 DEPENDENCIES
L<File::Find::Rule>,
L<String::BOM>.
=head1 SEE ALSO
=over
=back
=head1 REPOSITORY
L<https://github.com/michal-josef-spacek/File-Find-Rule-BOM>
=head1 AUTHOR
Michal Josef Å paÄek L<mailto:skim@cpan.org>
view all matches for this distribution
view release on metacpan or search on metacpan
requires 'Test::Pod';
requires 'Test::NoTabs';
requires 'Test::Perl::Metrics::Lite';
requires 'Test::Vars';
requires 'Test::File::Find::Rule';
requires 'File::Find::Rule::BOM';
};
view all matches for this distribution
view release on metacpan or search on metacpan
t/000-report-versions.t view on Meta::CPAN
return $self->_error("Did not provide a string to load");
}
# Byte order marks
# NOTE: Keeping this here to educate maintainers
# my %BOM = (
# "\357\273\277" => 'UTF-8',
# "\376\377" => 'UTF-16BE',
# "\377\376" => 'UTF-16LE',
# "\377\376\0\0" => 'UTF-32LE'
# "\0\0\376\377" => 'UTF-32BE',
# );
if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) {
return $self->_error("Stream has a non UTF-8 BOM");
} else {
# Strip UTF-8 bom if found, we'll just ignore it
$string =~ s/^\357\273\277//;
}
view all matches for this distribution
view release on metacpan or search on metacpan
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
BmFLAGS|5.009005||Viu
BmPREVIOUS|5.003007||Viu
BmRARE|5.003007||Viu
BmUSEFUL|5.003007||Viu
BOL|5.003007||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
bool|5.003007||Viu
boolSV|5.004000|5.003007|p
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
xs/ppport.h view on Meta::CPAN
(index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()),
} )
: die "invalid spec: $_" } qw(
AvFILLp|5.004050||p
AvFILL|||
BOM_UTF8|||
BhkDISABLE||5.024000|
BhkENABLE||5.024000|
BhkENTRY_set||5.024000|
BhkENTRY|||
BhkFLAGS|||
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/LoadLines.pm view on Meta::CPAN
It will transparently fetch data from the network if the provided file
name is a URL.
File::LoadLines automatically handles ASCII, Latin-1 and UTF-8 text.
When the file has a BOM, it handles UTF-8, UTF-16 LE and BE, and
UTF-32 LE and BE.
Recognized line terminators are NL (Unix, Linux), CRLF (DOS, Windows)
and CR (Mac)
lib/File/LoadLines.pm view on Meta::CPAN
$options->{encoding} //= 'Perl';
}
# Detect Byte Order Mark.
elsif ( $data =~ /^\xEF\xBB\xBF/ ) {
warn("$name is UTF-8 (BOM)\n") if $options->{debug};
$options->{encoding} = 'UTF-8';
$data = decode( "UTF-8", substr($data, 3) );
}
elsif ( $data =~ /^\xFE\xFF/ ) {
warn("$name is UTF-16BE (BOM)\n") if $options->{debug};
$options->{encoding} = 'UTF-16BE';
$data = decode( "UTF-16BE", substr($data, 2) );
}
elsif ( $data =~ /^\xFF\xFE\x00\x00/ ) {
warn("$name is UTF-32LE (BOM)\n") if $options->{debug};
$options->{encoding} = 'UTF-32LE';
$data = decode( "UTF-32LE", substr($data, 4) );
}
elsif ( $data =~ /^\xFF\xFE/ ) {
warn("$name is UTF-16LE (BOM)\n") if $options->{debug};
$options->{encoding} = 'UTF-16LE';
$data = decode( "UTF-16LE", substr($data, 2) );
}
elsif ( $data =~ /^\x00\x00\xFE\xFF/ ) {
warn("$name is UTF-32BE (BOM)\n") if $options->{debug};
$options->{encoding} = 'UTF-32BE';
$data = decode( "UTF-32BE", substr($data, 4) );
}
# No BOM, did user specify an encoding?
elsif ( $options->{encoding} ) {
warn("$name is ", $options->{encoding}, " (fallback)\n")
if $options->{debug};
$data = decode( $options->{encoding}, $data, 1 );
}
lib/File/LoadLines.pm view on Meta::CPAN
loadlines( $filename, $options );
}
=head1 SEE ALSO
There are currently no other modules that handle BOM detection and
line splitting.
I have a faint hope that future versions of Perl and Raku will deal
with this transparently, but I fear the worst.
view all matches for this distribution
view release on metacpan or search on metacpan
bind_match|5.003007||Viu
block_end|5.004000|5.004000|
block_gimme|5.004000|5.004000|u
blockhook_register|5.013003|5.013003|x
block_start|5.004000|5.004000|
BOM_UTF8|5.025005|5.003007|p
boolSV|5.004000|5.003007|p
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
_byte_dump_string|5.025006||Viu
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/ppport.h view on Meta::CPAN
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
lib/File/ppport.h view on Meta::CPAN
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
include/yyjson.h view on Meta::CPAN
- Read positive integer as uint64_t.
- Read negative integer as int64_t.
- Read floating-point number as double with round-to-nearest mode.
- Read integer which cannot fit in uint64_t or int64_t as double.
- Report error if double number is infinity.
- Report error if string contains invalid UTF-8 character or BOM.
- Report error on trailing commas, comments, inf and nan literals. */
static const yyjson_read_flag YYJSON_READ_NOFLAG = 0;
/** Read the input data in-situ.
This option allows the reader to modify and use input data to store string
include/yyjson.h view on Meta::CPAN
This function is thread-safe when:
1. The `dat` is not modified by other threads.
2. The `alc` is thread-safe or NULL.
@param dat The JSON data (UTF-8 without BOM), null-terminator is not required.
If this parameter is NULL, the function will fail and return NULL.
The `dat` will not be modified without the flag `YYJSON_READ_INSITU`, so you
can pass a `const char *` string and case it to `char *` if you don't use
the `YYJSON_READ_INSITU` flag.
@param len The length of JSON data in bytes.
include/yyjson.h view on Meta::CPAN
/**
Read a JSON string.
This function is thread-safe.
@param dat The JSON data (UTF-8 without BOM), null-terminator is not required.
If this parameter is NULL, the function will fail and return NULL.
@param len The length of JSON data in bytes.
If this parameter is 0, the function will fail and return NULL.
@param flg The JSON read options.
Multiple options can be combined with `|` operator. 0 means no options.
include/yyjson.h view on Meta::CPAN
/**
Read a JSON number.
This function is thread-safe when data is not modified by other threads.
@param dat The JSON data (UTF-8 without BOM), null-terminator is required.
If this parameter is NULL, the function will fail and return NULL.
@param val The output value where result is stored.
If this parameter is NULL, the function will fail and return NULL.
The value will hold either UINT or SINT or REAL number;
@param flg The JSON read options.
include/yyjson.h view on Meta::CPAN
/**
Read a JSON number.
This function is thread-safe when data is not modified by other threads.
@param dat The JSON data (UTF-8 without BOM), null-terminator is required.
If this parameter is NULL, the function will fail and return NULL.
@param val The output value where result is stored.
If this parameter is NULL, the function will fail and return NULL.
The value will hold either UINT or SINT or REAL number;
@param flg The JSON read options.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/Raw/Separated.pm view on Meta::CPAN
Empty unquoted field becomes C<undef>. Quoted empty (C<"">) stays the
empty string. Default false (always returns C<"">).
=item C<binary>
Skip UTF-8 BOM stripping and skip C<sv_utf8_decode> on each field.
Default false.
=item C<header>
Controls whether rows are emitted as arrayrefs (default) or hashrefs.
view all matches for this distribution
view release on metacpan or search on metacpan
include/ppport.h view on Meta::CPAN
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
include/ppport.h view on Meta::CPAN
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/Text/CSV.pm view on Meta::CPAN
=item encoding
Encoding to open the file with. Default encoding is UTF-8, unless
header processing is enabled and the file starts with a byte order
mark (BOM).
=item append
If true, new records written will be appended to the file.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/File/ValueFile/Simple/Reader.pm view on Meta::CPAN
delete $self->{features};
while (my $line = <$fh>) {
$line =~ s/\r?\n$//;
$line =~ s/#.*$//;
$line =~ s/^\xEF\xBB\xBF//; # skip BOMs.
$line =~ s/\s+/ /g;
$line =~ s/ $//;
$line =~ s/^ //;
next unless length $line;
view all matches for this distribution
view release on metacpan or search on metacpan
easyxs/ppport.h view on Meta::CPAN
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
easyxs/ppport.h view on Meta::CPAN
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
t/000-report-versions.t view on Meta::CPAN
return $self->_error("Did not provide a string to load");
}
# Byte order marks
# NOTE: Keeping this here to educate maintainers
# my %BOM = (
# "\357\273\277" => 'UTF-8',
# "\376\377" => 'UTF-16BE',
# "\377\376" => 'UTF-16LE',
# "\377\376\0\0" => 'UTF-32LE'
# "\0\0\376\377" => 'UTF-32BE',
# );
if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) {
return $self->_error("Stream has a non UTF-8 BOM");
} else {
# Strip UTF-8 bom if found, we'll just ignore it
$string =~ s/^\357\273\277//;
}
view all matches for this distribution
view release on metacpan or search on metacpan
bind_match|5.003007||Viu
block_end|5.004000|5.004000|
block_gimme|5.004000|5.004000|u
blockhook_register|5.013003|5.013003|x
block_start|5.004000|5.004000|
BOM_UTF8|5.025005|5.003007|p
boolSV|5.004000|5.003007|p
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
_byte_dump_string|5.025006||Viu
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
share/iso10383_mic.csv view on Meta::CPAN
XBLB,BANJA LUKA STOCK EXCHANGE,BA,BOSNIA AND HERZEGOVINA,BANJA LUKA, ,October 2005,Active
XBLN,BLUENEXT,FR,FRANCE,PARIS,,April 2011,Active
XBNV,"BOLSA NACIONAL DE VALORES, S.A.",CR,COSTA RICA,SAN JOSE,BNV,June 2005,Active
XBOG,BOLSA DE VALORES DE COLOMBIA,CO,COLOMBIA,BOGOTA,BVC,June 2005,Active
XBOL,BOLSA BOLIVIANA DE VALORES S.A.,BO,BOLIVIA,LA PAZ, ,June 2005,Active
XBOM,BSE LTD.,IN,INDIA,MUMBAI,MSE,September 2011,Active
XBOS,NASDAQ OMX BX,US,UNITED STATES OF AMERICA,BOSTON,BSE,February 2009,Active
XBOT,BOTSWANA STOCK EXCHANGE,BW,BOTSWANA,GABORONE, ,June 2005,Active
XBOX,BOSTON OPTIONS EXCHANGE,US,UNITED STATES OF AMERICA,BOSTON,BOX,June 2005,Active
XBRA,BRATISLAVA STOCK EXCHANGE,SK,SLOVAKIA,BRATISLAVA,BSSE,June 2005,Active
XBRD,NYSE EURONEXT - EURONEXT BRUSSELS - DERIVATIVES,BE,BELGIUM,BRUSSELS, ,November 2007,Active
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Finance/Quote/YahooJSON.pm view on Meta::CPAN
#!/usr/bin/perl -w
# This module is based on the Finance::Quote::BSERO module
# It was first called BOMSE but has been renamed to yahooJSON
# since it gets a lot of quotes besides Indian
#
# The code has been modified by Abhijit K to
# retrieve stock information from Yahoo Finance through json calls
#
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Finance/QuoteHist/Generic.pm view on Meta::CPAN
my @patterns = $self->patterns(@_);
sub {
my $data = shift;
return [] unless defined $data;
my @csv_lines = ref $data ? <$data> : split("\n", $data);
# BOM squad (byte order mark, as csv from google tends to be)
if ($csv_lines[0] =~ s/^\xEF\xBB\xBF//) {
for my $i (0 .. $#csv_lines) {
utf8::decode($csv_lines[$i]);
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/FrameMaker/MifTree/MifTreeTags view on Meta::CPAN
DXmlFileEncoding
DXmlPublicId
DXmlStandAlone
DXmlStyleSheet
DXmlSystemId
DXmlUseBOM
DXmlVersion
DXmlWellFormed
AcrobatElements
Book
BNextUnique
lib/FrameMaker/MifTree/MifTreeTags view on Meta::CPAN
BXmlDocType
BXmlEncoding
BXmlFileEncoding
BXmlStandAlone
BXmlStyleSheet
BXmlUseBOM
BXmlVersion
BXmlWellFormed
BookXRef
BookUpdateReferences
)],
lib/FrameMaker/MifTree/MifTreeTags view on Meta::CPAN
BXmlDocType => 'string',
BXmlEncoding => 'string',
BXmlFileEncoding => 'string',
BXmlStandAlone => 'integer',
BXmlStyleSheet => 'string',
BXmlUseBOM => 'integer',
BXmlVersion => 'string',
BXmlWellFormed => 'integer',
BaseAngle => 'integer',
BaseCharWithRubi => 'data',
BaseCharWithSuper => 'data',
lib/FrameMaker/MifTree/MifTreeTags view on Meta::CPAN
DXmlFileEncoding => 'string',
DXmlPublicId => 'string',
DXmlStandAlone => 'integer',
DXmlStyleSheet => 'string',
DXmlSystemId => 'string',
DXmlUseBOM => 'integer',
DXmlVersion => 'string',
DXmlWellFormed => 'integer',
DashSegment => 'dimension',
DashedStyle => 'keyword',
DataLinkEnd => 'empty',
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Future/Batch/ppport.h view on Meta::CPAN
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
lib/Future/Batch/ppport.h view on Meta::CPAN
#endif
#endif
#if 'A' == 65
#ifndef BOM_UTF8
# define BOM_UTF8 "\xEF\xBB\xBF"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xEF\xBF\xBD"
#endif
#elif '^' == 95
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x73\x66\x73"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x73\x73\x71"
#endif
#elif '^' == 176
#ifndef BOM_UTF8
# define BOM_UTF8 "\xDD\x72\x65\x72"
#endif
#ifndef REPLACEMENT_CHARACTER_UTF8
# define REPLACEMENT_CHARACTER_UTF8 "\xDD\x72\x72\x70"
#endif
view all matches for this distribution
view release on metacpan or search on metacpan
sub HERO () { 0 } # where in @animates the player lives (also ID)
sub GOAL () { 1 }
sub SCRAM () { 2 } # animate IDs
sub BOMB () { 3 }
sub XX () { 0 } # points, and @animates index slots
sub YY () { 1 }
sub IX () { 2 } # animate inertia
sub IY () { 3 }
my $cards_played = ~0; # score (lower is better)
my @collisions;
$collisions[HERO][GOAL] = \&collide_hero_goal;
$collisions[HERO][SCRAM] = \&collide_hero_scram;
$collisions[HERO][BOMB] = \&collide_hero_bomb;
$collisions[GOAL][HERO] = \&collide_hero_goal;
$collisions[GOAL][SCRAM] = \&collide_gate_scram;
my $clicks; # quadtree foo
if ( $level >= 4 ) {
my $n = 29;
$n = 17 if $level == 5;
for ( 1 .. $n ) {
push @animates,
make_animate( BOMB, 'Bomb', random_point_unique(), 0, [$bombi] );
place_animate( $animates[-1] );
}
}
# NOTE you could instead first collect everything and shuffle here
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
sub unalt_screen () { "\e[?1049l" }
# WHAT Animates and such can be
sub HERO () { 0 }
sub MONST () { 1 }
sub BOMB () { 2 }
sub GEM () { 3 }
sub FLOOR () { 4 }
sub WALL () { 5 }
sub LADDER () { 6 }
sub STAIR () { 7 }
sub STATUE () { 8 }
sub BOMB_COST () { 2 }
sub GEM_VALUE () { 1 }
# for the Level Map Cell (LMC)
sub WHERE () { 0 }
sub GROUND () { 1 }
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
sub UPDATE () { 4 }
sub LMC () { 5 }
sub BLACK_SPOT () { 6 }
sub GEM_STASH () { 0 }
sub BOMB_STASH () { 1 }
sub GEM_ODDS () { 1 }
sub GEM_ODDS_ADJUST () { 0.05 }
sub START_GEMS () { 0 }
sub START_BOMBS () { 1 }
sub GRAPH_NODE () { 0 }
sub GRAPH_WEIGHT () { 1 }
sub GRAPH_POINT () { 2 }
our %CharMap = (
'o' => BOMB,
'.' => FLOOR,
'*' => GEM,
'@' => HERO,
'=' => LADDER,
'P' => MONST,
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
our @Styles =
qw(Abstract Art-Deco Brutalist Egyptian Greek Impressionist Post-Modern Roman Romantic);
our $Style = $Styles[ rand @Styles ];
our %Things = (
BOMB, [ BOMB, "\e[31mo\e[0m", ITEM ],
FLOOR, [ FLOOR, "\e[33m.\e[0m", FLOOR ],
GEM, [ GEM, "\e[32m*\e[0m", ITEM ],
LADDER, [ LADDER, "\e[37m=\e[0m", LADDER ],
STAIR, [ FLOOR, "\e[37m%\e[0m", STAIR ],
STATUE, [ FLOOR, "\e[1;33m&\e[0m", STATUE ],
WALL, [ WALL, "\e[35m#\e[0m", WALL ],
);
our %Descriptions = (
BOMB, 'Bomb. Avoid.',
FLOOR, 'Empty cell.',
GEM, 'A gem. Get these.',
HERO, 'The much suffering hero.',
LADDER, 'A ladder.',
MONST, $Monst_Name . '. Wants to kill you.',
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
STATUE, 'Empty cell with decorative statue.',
WALL, 'A wall.',
);
$Animates[HERO]->@[ WHAT, DISP, TYPE, STASH, UPDATE ] = (
HERO, "\e[1;33m\@\e[0m", ANI, [ START_GEMS, START_BOMBS ],
\&update_hero
);
our %Interact_With = (
HERO, # the target of the mover
sub {
my ( $mover, $target ) = @_;
game_over_monster() if $mover->[WHAT] == MONST;
game_over_bomb() if $mover->[WHAT] == BOMB;
grab_gem( $target, $mover );
},
MONST,
sub {
my ( $mover, $target ) = @_;
game_over_monster() if $mover->[WHAT] == HERO;
if ( $mover->[WHAT] == BOMB ) {
my @cells = map { kill_animate( $_, 1 ); $_->[LMC][WHERE] } $mover,
$target;
redraw_ref( \@cells );
$Explosions{ join ',', $target->[LMC][WHERE]->@* } = $target;
} elsif ( $mover->[WHAT] == GEM ) {
grab_gem( $target, $mover );
}
},
BOMB,
sub {
my ( $mover, $target ) = @_;
game_over_bomb() if $mover->[WHAT] == HERO;
if ( $mover->[WHAT] == MONST ) {
my @cells = map { kill_animate( $_, 1 ); $_->[LMC][WHERE] } $mover,
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
post_message("\@ $Animates[HERO][LMC][WHERE]->@* R $Rotation");
return MOVE_FAILED;
},
'$' => sub {
post_message( 'You have '
. $Animates[HERO][STASH][BOMB_STASH]
. ' bombs and '
. $Animates[HERO][STASH][GEM_STASH]
. ' gems.' );
return MOVE_FAILED;
},
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
load_level();
print clear_screen(), draw_level();
post_message( 'Level '
. $Level
. ' (You have '
. $Animates[HERO][STASH][BOMB_STASH]
. ' bombs and '
. $Animates[HERO][STASH][GEM_STASH]
. ' gems.)' );
return MOVE_NEWLVL;
} else {
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
}
},
'B' => sub {
my $lmc = $Animates[HERO][LMC];
return MOVE_FAILED, 'You have no bombs (make them from gems).'
if $Animates[HERO][STASH][BOMB_STASH] < 1;
return MOVE_FAILED, 'There is already an item in this cell.'
if defined $lmc->[ITEM];
$Animates[HERO][STASH][BOMB_STASH]--;
make_item( $lmc->[WHERE], BOMB, 0 );
return MOVE_OK;
},
'M' => sub {
return MOVE_FAILED, 'You need more gems.'
if $Animates[HERO][STASH][GEM_STASH] < BOMB_COST;
$Animates[HERO][STASH][GEM_STASH] -= BOMB_COST;
post_message(
'You now have ' . ++$Animates[HERO][STASH][BOMB_STASH] . ' bombs' );
return MOVE_OK;
},
'Q' => sub { game_over('Be seeing you...') },
'q' => sub { game_over('Be seeing you...') },
"\003" => sub { # <C-c>
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
my $colnum = 0;
for my $v ( split //, $line ) {
my $c = $CharMap{$v} // game_over("Unknown character $v at $file:$.");
my $point = [ $colnum++, $rownum ]; # PCOL, PROW (x, y)
if ( exists $Things{$c} ) {
if ( $c eq BOMB ) {
push $LMap->[$rownum]->@*, [ $point, $Things{ FLOOR, } ];
make_item( $point, BOMB, 0 );
} elsif ( $c eq GEM ) {
push $LMap->[$rownum]->@*, [ $point, $Things{ FLOOR, } ];
make_item( $point, GEM, GEM_VALUE );
} else {
push $LMap->[$rownum]->@*, [ $point, $Things{$c} ];
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
sub make_monster {
my ($point) = @_;
my $monst;
my $ch = substr $Monst_Name, 0, 1;
# STASH replicates that of the HERO for simpler GEM handling code
# though the BOMB_STASH is instead used for GEM_ODDS
$monst->@[ WHAT, DISP, TYPE, STASH, UPDATE, LMC ] = (
MONST, "\e[1;33m$ch\e[0m", ANI, [ 0, 0.0 ],
\&update_monst, $LMap->[ $point->[PROW] ][ $point->[PCOL] ]
);
push @Animates, $monst;
lib/Game/PlatformsOfPeril.pm view on Meta::CPAN
post_message( ' '
. $Things{ STATUE, }[DISP]
. ' - a large granite statue done in the' );
post_message( ' ' . $Style . ' style' );
post_message( ' '
. $Things{ BOMB, }[DISP]
. ' - Bomb '
. $Things{ GEM, }[DISP]
. ' - Gem (get these)' );
post_message('');
post_message(' h j k l - move');
post_message(' < > - activate left or right boot');
post_message(' B - drop a Bomb');
post_message(
' M - make a Bomb (consumes ' . BOMB_COST . ' Gems)' );
post_message( ' % - when on '
. $Things{ STAIR, }[DISP]
. ' goes to the next level' );
post_message(' . space - pass a turn (handy when falling)');
post_message('');
post_message(' Q q - quit the game (no save)');
post_message(' $ - display Bomb and Gem counts');
post_message(' ? - post these help messages');
post_message('');
post_message( 'You have '
. $Animates[HERO][STASH][BOMB_STASH]
. ' bombs and '
. $Animates[HERO][STASH][GEM_STASH]
. ' gems.' );
}
view all matches for this distribution