Brought all packages under eye of strict, warnings and love of Carp, For
[sdlgit/SDL_perl.git] / lib / SDL / Cdrom.pm
1 #       Cdrom.pm
2 #
3 #       a SDL cdrom manipluation module
4 #
5 #       Copyright (C) 2000,2002 David J. Goehrig
6 #
7
8 package SDL::Cdrom;
9 use strict;
10 use warnings;
11 use Carp;
12
13 BEGIN {
14         use Exporter();
15         use vars qw(@ISA @EXPORT);
16         @ISA = qw(Exporter);
17         @EXPORT = qw/ &CD_NUM_DRIVES /;
18 }
19
20 sub new {
21         my $proto = shift;
22         my $class = ref($proto) || $proto;
23         my $self;
24         my $number = shift;
25         $self = \SDL::CDOpen($number);
26         croak SDL::GetError() if ( SDL::CD_ERROR() eq SDL::CDStatus($$self));
27         bless $self,$class;
28         return $self;
29 }
30
31 sub DESTROY {
32         my $self = shift;
33         SDL::CDClose($$self);
34 }
35
36 sub CD_NUM_DRIVES {
37         return SDL::CDNumDrives();
38 }
39
40 sub name ($) {
41         my $self = shift;
42         return SDL::CDName($$self);
43 }
44
45 sub status ($) {
46         my $self = shift;
47         return SDL::CDstatus($$self);
48 }
49
50 sub play ($$$;$$) {
51         my ($self,$start,$length,$fs,$fl) = @_;
52         return SDL::CDPlayTracks($$self,$start,$length,$fs,$fl);
53 }
54
55 sub pause ($) {
56         my $self = shift;
57         return SDL::CDPause($$self);
58 }
59
60 sub resume ($) {
61         my $self = shift;
62         return SDL::CDResume($$self);
63 }
64
65 sub stop ($) {
66         my $self = shift;
67         return SDL::CDStop($$self);
68 }
69
70 sub eject ($) {
71         my $self = shift;
72         return SDL::CDEject($$self);
73 }
74
75 sub id ($) {
76         my $self = shift;
77         return SDL::CDId($$self);
78 }
79
80 sub num_tracks ($) {
81         my $self = shift;
82         return SDL::CDNumTracks($$self);
83 }
84
85 my $buildtrack = sub {
86         my $ptr = shift;
87         my %track = ();
88         $track{-id} = SDL::CDTrackId($ptr);
89         $track{-type} = SDL::CDTrackType($ptr);
90         $track{-length} = SDL::CDTrackLength($ptr);
91         $track{-offset} = SDL::CDTrackOffset($ptr);
92         return \%track;
93 };
94
95 sub track {
96         my $self = shift;
97         my $number = shift;
98         return &$buildtrack(SDL::CDTrack($$self,$number));
99 }
100
101 sub current {
102         my $self = shift;
103         return $self->track(SDL::CDCurTrack($$self));
104 }
105
106 sub current_frame {
107         my $self = shift;
108         return SDL::CDCurFrame($$self);
109 }
110
111 1;
112
113 __END__;
114
115 =pod
116
117
118
119 =head1 NAME
120
121 SDL::Cdrom - a SDL perl extension for managing CD-ROM drives
122
123 =head1 SYNOPSIS
124
125         use SDL::Cdrom;
126         $cdrom = SDL::Cdrom->new(0);
127         $cdrom->play();
128
129 =head1 EXPORTS
130
131 =over 4
132
133 =item *
134
135 C<CD_NUM_DRIVES>.
136
137 =back
138
139 =head1 DESCRIPTION
140
141 Create a new SDL::Cdrom object. The passed $id is the number of the drive,
142 whereas 0 is the first drive etc.
143         
144         use SDL::Cdrom;
145         my $drive => SDL::Cdrom->new($id);
146
147 =head1 METHODS
148
149 =head2 CD_NUM_DRIVES()
150
151 Returns the number of CD-ROM drives present.
152
153 =head2 name()
154
155 Returns the system dependent name of the CD-ROM device.
156
157 =head2 status()
158
159 Return the status of the drive.
160
161 =head2 play()
162
163 Play a track.
164
165 =head2 pause()
166
167 Pause the playing.
168
169 =head2 resume()
170
171 Resume the playing.
172
173 =head2 stop()
174
175 Stop the playing.
176
177 =head2 eject()
178
179 Eject the medium in the drive.
180
181 =head2 id()
182
183 Return the ID of the drive.
184
185 =head2 num_tracks()
186
187 Return the number of tracks on the medium.
188
189 =head2 track()
190
191 Returns the track description
192
193 =head2 current()
194
195 Return the current played track number.
196
197 =head2 current_frame()
198
199 Return the current frame.
200
201 =head1 AUTHORS
202
203 David J. Goehrig
204 Documentation by Tels <http://bloodgate.com/>.
205
206 =head1 SEE ALSO
207
208 L<perl> L<SDL::Mixer> L<SDL::App>.
209
210 =cut