debugging help. Also removed forced die in Build of MSWin32.
# Copyright (C) 2009 Kartik Thakore
use strict;
-
+use warnings;
+use Carp;
use lib 'make/lib';
use SDL::Build;
if ($? >> 8)
{
- die "SDL doesn't appear to be installed.\n" .
+ croak "SDL doesn't appear to be installed.\n" .
"Please check that sdl-config is in your path and try again.\n";
}
#
# Copyright (C) 2004 David J. Goehrig
-#
+# Copyright (C) 2009 Kartik Thakore
package SDL;
use strict;
+use warnings;
+use Carp;
+
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
sub verify (\%@) {
my ($options,@valid_options) = @_;
for (keys %$options) {
- die "Invalid option $_\n" unless in ($_, @valid_options);
+ croak "Invalid option $_\n" unless in ($_, @valid_options);
}
}
package SDL::App;
use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::Event;
use SDL::Surface;
}
my $self = \SDL::SetVideoMode($w,$h,$d,$f);
$$self
- or die SDL::GetError();
+ or croak SDL::GetError();
if ($ic and -e $ic) {
my $icon = new SDL::Surface -name => $ic;
SDL::GLSetAttribute($mode,$value);
}
my $returns = SDL::GLGetAttribute($mode);
- die "SDL::App::attribute failed to get GL attribute" if ($$returns[0] < 0);
+ croak "SDL::App::attribute failed to get GL attribute" if ($$returns[0] < 0);
$$returns[1];
}
C<SDL::App::attribute> allows one to set and get GL attributes. By passing a value
in addition to the attribute selector, the value will be set. C<SDL:::App::attribute>
-always returns the current value of the given attribute, or dies on failure.
+always returns the current value of the given attribute, or croaks on failure.
=head1 AUTHOR
David J. Goehrig
+Kartik Thakore
=head1 SEE ALSO
package SDL::Cdrom;
use strict;
+use warnings;
+use Carp;
BEGIN {
use Exporter();
my $self;
my $number = shift;
$self = \SDL::CDOpen($number);
- die SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
+ croak SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
bless $self,$class;
return $self;
}
package SDL::Color;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
if ($options{-color}) {
$self = \$options{-color};
} elsif ($options{-pixel} && $options{-surface}) {
- die "SDL::Color::new requires an SDL::Surface"
+ croak "SDL::Color::new requires an SDL::Surface"
unless !$SDL::DEBUG || $options{-surface}->isa("SDL::Surface");
$self = \SDL::NewColor(SDL::GetRGB(${$options{-surface}}, $options{-pixel}));
} else {
push @color, $options{-blue} || $options{-b} || 0;
$self = \SDL::NewColor(@color);
}
- die "Could not create color, ", SDL::GetError(), "\n"
+ croak "Could not create color, ", SDL::GetError(), "\n"
unless ($$self);
bless $self, $class;
}
}
sub pixel {
- die "SDL::Color::pixel requires an SDL::Surface"
+ croak "SDL::Color::pixel requires an SDL::Surface"
unless !$SDL::DEBUG || $_[1]->isa("SDL::Surface");
SDL::MapRGB(${$_[1]},$_[0]->r(),$_[0]->g(),$_[0]->b());
}
package SDL::Cursor;
use strict;
+use warnings;
+use Carp;
sub new {
my $proto = shift;
package SDL::Event;
use strict;
+use warnings;
+use Carp;
+
use SDL;
sub new {
package SDL::Font;
use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::SFont;
use SDL::Surface;
package SDL::MPEG;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
my $self;
if ( $options{-from} ) {
- die "SDL::MPEG::new -from requires a SDL::Video object\n"
+ croak "SDL::MPEG::new -from requires a SDL::Video object\n"
unless $options{-from}->isa('SDL::Video');
$self = \SDL::SMPEGGetInfo(${$options{-from}});
package SDL::Mixer;
use strict;
+use warnings;
+use Carp;
+
use SDL;
use SDL::Sound;
use SDL::Music;
my $size = $options{-size} || 4096;
unless ( $SDL::Mixer::initialized ) {
SDL::MixOpenAudio($frequency,$format,$channels,$size ) &&
- die SDL::GetError();
+ croak SDL::GetError();
$SDL::Mixer::initialized = 1;
} else {
++$SDL::Mixer::initialized;
package SDL::Music;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
package SDL::OpenGL;
+use strict;
+use warnings;
+use Carp;
+
require Exporter;
require DynaLoader;
use vars qw(
use SDL;
use SDL::OpenGL::Constants;
+
bootstrap SDL::OpenGL;
for ( keys %SDL::OpenGL:: ) {
if (/^gl/) {
package SDL::Palette;
use strict;
+use warnings;
+use Carp;
# NB: there is no palette destructor because most of the time the
# palette will be owned by a surface, so any palettes you create
package SDL::Rect;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
package SDL::Sound;
use strict;
-
+use warnings;
+use Carp;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
package SDL::Surface;
use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::SFont;
use SDL::Color;
$self = \SDL::CreateRGBSurface($f,$w,$h,$d,$r,$g,$b,$a);
}
}
- die "SDL::Surface::new failed. ", SDL::GetError()
+ croak "SDL::Surface::new failed. ", SDL::GetError()
unless ( $$self);
bless $self,$class;
return $self;
}
sub pixel {
- die "SDL::Surface::pixel requires a SDL::Color"
+ croak "SDL::Surface::pixel requires a SDL::Color"
if $_[3] && $SDL::DEBUG && !$_[3]->isa("SDL::Color");
$_[3] ?
new SDL::Color -color => SDL::SurfacePixel(${$_[0]},$_[1],$_[2],${$_[3]}) :
}
sub fill {
- die "SDL::Surface::fill requires a SDL::Rect object"
+ croak "SDL::Surface::fill requires a SDL::Rect object"
unless !$SDL::DEBUG || $_[1] == 0 || $_[1]->isa('SDL::Rect');
- die "SDL::Surface::fill requires a SDL::Color object"
+ croak "SDL::Surface::fill requires a SDL::Color object"
unless !$SDL::DEBUG || $_[2]->isa('SDL::Color');
if ($_[1] == 0 ) {
SDL::FillRect(${$_[0]},0,${$_[2]});
my $self = shift;;
if ($SDL::DEBUG) {
for (@_) {
- die "SDL::Surface::update requires SDL::Rect objects"
+ croak "SDL::Surface::update requires SDL::Rect objects"
unless $_->isa('SDL::Rect');
}
}
sub blit {
if ($SDL::DEBUG) {
- die "SDL::Surface::blit requires SDL::Rect objects"
+ croak "SDL::Surface::blit requires SDL::Rect objects"
unless ($_[1] == 0 || $_[1]->isa('SDL::Rect'))
&& ($_[3] == 0 || $_[3]->isa('SDL::Rect'));
- die "SDL::Surface::blit requires SDL::Surface objects"
+ croak "SDL::Surface::blit requires SDL::Surface objects"
unless $_[2]->isa('SDL::Surface');
}
SDL::BlitSurface(map { $_ != 0 ? ${$_} : $_ } @_);
my $self = shift;
my $start = shift;
for (@_) {
- die "SDL::Surface::set_colors requires SDL::Color objects"
+ croak "SDL::Surface::set_colors requires SDL::Color objects"
unless !$SDL::DEBUG || $_->isa('SDL::Color');
}
return SDL::SetColors($$self, $start, map { ${$_} } @_);
}
sub set_color_key {
- die "SDL::Surface::set_color_key requires a SDL::Color object"
+ croak "SDL::Surface::set_color_key requires a SDL::Color object"
unless !$SDL::DEBUG || (ref($_[2]) && $_[2]->isa('SDL::Color'));
SDL::SetColorKey(${$_[0]},$_[1],${$_[2]});
}
package SDL::TTFont;
use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::Surface;
$self->{-fg} = $options{-foreground} || $options{-fg} || $SDL::Color::black;
$self->{-bg} = $options{-background} || $options{-bg} || $SDL::Color::white;
- die "SDL::TTFont::new requires a -name\n"
+ croak "SDL::TTFont::new requires a -name\n"
unless ($$self{-name});
- die "SDL::TTFont::new requires a -size\n"
+ croak "SDL::TTFont::new requires a -size\n"
unless ($$self{-size});
$self->{-font} = SDL::TTFOpenFont($self->{-name},$self->{-size});
- die "Could not open font $$self{-name}, ", SDL::GetError(), "\n"
+ croak "Could not open font $$self{-name}, ", SDL::GetError(), "\n"
unless ($self->{-font});
bless $self,$class;
sub print {
my ($self,$surface,$x,$y,@text) = @_;
- die "Print requies an SDL::Surface"
+ croak "Print requies an SDL::Surface"
unless( ref($surface) && $surface->isa("SDL::Surface") );
SDL::FreeSurface($self->{-surface}) if ($$self{-surface});
$$self{-surface} = SDL::TTFPutString($$self{-font},$$self{-mode},
$$surface,$x,$y,${$$self{-fg}},${$$self{-bg}},join("",@text));
- die "Could not print \"", join("",@text), "\" to surface, ",
+ croak "Could not print \"", join("",@text), "\" to surface, ",
SDL::GetError(), "\n" unless ($$self{-surface});
}
$$self{-mode} = UNICODE_BLENDED();
}
-die "Could not initialize True Type Fonts\n"
+croak "Could not initialize True Type Fonts\n"
if ( SDL::TTFInit() < 0);
1;
package SDL::Timer;
use strict;
+use warnings;
+use Carp;
use SDL;
sub new {
verify(%options,qw/ -delay -times -d -t /);
- die "SDL::Timer::new no delay specified\n"
+ croak "SDL::Timer::new no delay specified\n"
unless ($options{-delay});
$$self{-delay} = $options{-delay} || $options{-d} || 0;
$$self{-times} = $options{-times} || $options{-t} || 0;
$$self{-routine} = sub { &$func; $$self{-delay}};
}
$$self{-timer} = SDL::NewTimer($$self{-delay},$$self{-routine});
- die "Could not create timer, ", SDL::GetError(), "\n"
+ croak "Could not create timer, ", SDL::GetError(), "\n"
unless ($self->{-timer});
bless $self,$class;
return $self;
package SDL::Tool::Font;
+use strict;
+use warnings;
+use Carp;
+
use SDL;
use SDL::Font;
use SDL::TTFont;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
- $self = {};
+ my $self = {};
my %option = @_;
verify (%option, qw/ -sfont -ttfont -size -fg -bg -foreground -background
}
}
} else {
- die "SDL::Tool::Font requires either a -sfont or -ttfont";
+ croak "SDL::Tool::Font requires either a -sfont or -ttfont";
}
bless $self,$class;
$self;
sub print {
my ($self,$surface,$x,$y,@text) = @_;
- die "Tool::Font::print requires a SDL::Surface\n"
+ croak "Tool::Font::print requires a SDL::Surface\n"
unless ($surface->isa('SDL::Surface'));
if ($$self{-font}->isa('SDL::Font')) {
$$self{-font}->use();
package SDL::Tool::Graphic;
+use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::Config;
require SDL::Surface;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
- $self = {};
+ my $self = {};
bless $self, $class;
$self;
}
sub zoom {
my ( $self, $surface, $zoomx, $zoomy, $smooth) = @_;
- die "SDL::Tool::Graphic::zoom requires an SDL::Surface\n"
+ croak "SDL::Tool::Graphic::zoom requires an SDL::Surface\n"
unless ( ref($surface) && $surface->isa('SDL::Surface'));
my $tmp = $$surface;
$$surface = SDL::GFXZoom($$surface, $zoomx, $zoomy, $smooth);
sub rotoZoom {
my ( $self, $surface, $angle, $zoom, $smooth) = @_;
- die "SDL::Tool::Graphic::rotoZoom requires an SDL::Surface\n"
+ croak "SDL::Tool::Graphic::rotoZoom requires an SDL::Surface\n"
unless ( ref($surface) && $surface->isa('SDL::Surface'));
my $tmp = $$surface;
$$surface = SDL::GFXRotoZoom($$surface, $angle, $zoom, $smooth);
sub grayScale {
my ( $self, $surface ) = @_;
+ my $workingSurface;
if($surface->isa('SDL::Surface')) {
- $workingSurface = $$surface;
+ $workingSurface = $$surface;
} else {
$workingSurface = $surface;
}
sub invertColor {
my ( $self, $surface ) = @_;
+ my $workingSurface;
if($surface->isa('SDL::Surface')) {
$workingSurface = $$surface;
} else {
}
}
-die "SDL::Tool::Graphic requires SDL_gfx support\n"
+croak "SDL::Tool::Graphic requires SDL_gfx support\n"
unless SDL::Config->has('SDL_gfx');
package SDL::Video;
use strict;
+use warnings;
+use Carp;
use SDL;
use SDL::Surface;
use SDL::MPEG;
verify (%options, qw/ -name -audio / ) if $SDL::DEBUG;
- my $n = $options{-name} || die "SDL::Video must supply a filename to SDL::Video::new\n";
+ my $n = $options{-name} || croak "SDL::Video must supply a filename to SDL::Video::new\n";
my $a = $options{'-audio'} ? 1 : 0;
my $info = new SDL::MPEG();
}
sub display {
- die "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
+ croak "SDL::Video::Display requires a SDL::Surface\n" unless $_[1]->isa('SDL::Surface');
SDL::SMPEGSetDisplay( ${$_[0]}, ${$_[1]}, 0);
}
}
sub region {
- die "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
+ croak "SDL::Video::region requires a SDL::Rect\n" unless $_[1]->isa('SDL::Rect');
SDL::SMPEGDisplayRegion(${$_[0]},${$_[1]});
}
package SDL::Build;
use strict;
+use warnings;
+use Carp;
use base 'Module::Build';
use File::Spec;
'SDL', 'Build', ucfirst( $os ) . '.pm' );
my $module = 'SDL::Build::' . ucfirst( $os );
- require $modpath or die "No module for $os platform\n";
+ require $modpath or croak "No module for $os platform\n";
return $module;
}
for my $library (@{ $subsystem->{libraries} })
{
my $lib = $libraries->{$library}
- or die "Unknown library '$library' for '$name'\n";
+ or croak "Unknown library '$library' for '$name'\n";
my ($inc_dir, $link_dir) =
$self->find_header( $lib->{header}, \%includes_libs );
$text =~ s/^\t//gm;
- open my $file, '>', $path or die "Cannot write to '$path': $!\n";
+ open my $file, '>', $path or croak "Cannot write to '$path': $!\n";
print $file $text;
}
package SDL::Build::MSWin32;
use strict;
-
+use warnings;
+usr Carp;
use base 'SDL::Build';
use File::Spec::Functions;
sub fetch_includes
{
- die "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE};
+ croak "Environment variable INCLUDE is empty\n" unless $ENV{INCLUDE};
return map { $_ => 1 } grep { $_ } split( ';', $ENV{INCLUDE} );
}
{
for my $key (qw( LIBS PATH ))
{
- die "Environment variable $key is empty\n" unless $ENV{$key};
+ carp "Environment variable $key is empty\n" unless $ENV{$key};
+ carp "This will probably fail the compile \nSet $key manually or try building anyway\n" unless $ENV{$key};
}
my ( $self, $header, $includes ) = @_;
return 'mesa_gl' if $vendor eq 'MESA';
return 'ms_gl' if $vendor eq 'MS';
- die "Unrecognized GL vendor '$vendor'\n";
+ croak "Unrecognized GL vendor '$vendor'\n";
}
sub ms_gl_subsystems
#!/usr/bin/env perl
use SDL;
+use Carp;
-die "Could not initialize SDL: ", SDL::GetError()
+croak "Could not initialize SDL: ", SDL::GetError()
if ( 0 > SDL::Init(SDL_INIT_AUDIO()));
$ARGV[0] ||= 'data/sample.wav';
-die "usage: $0 [wavefile]\n"
+croak "usage: $0 [wavefile]\n"
if ( in $ARGV[0], qw/ -h --help -? /);
my ($wav_spec,$wav_buffer,$wav_len,$wav_pos) = (0,0,0,0);
($wav_spec,$wav_buffer,$wav_len) = @$wave;
-die "Could not load wav file $ARGV[0], ", SDL::GetError(), "\n" unless ( $wav_len );
+croak "Could not load wav file $ARGV[0], ", SDL::GetError(), "\n" unless ( $wav_len );
-die "Could not open audio ", SDL::GetError()
+croak "Could not open audio ", SDL::GetError()
if (0 > SDL::OpenAudio($wav_spec,$fillerup));
SDL::PauseAudio(0);