Can someone explain this to me?

S

Stan Brown

I'm trying to use the Video::Capture module (which has no docs) to capture
images from multple cards. I've finally found the following snippet of
code in the perl module itself:

sub new(;$) {
my $class = shift;
my $device = shift || "/dev/video0";
my $self = bless { device => $device }, $class;


It looks like the devie needs to be passed as the 2nd argument to the new
call., and if a 2nd arg is not received it defaults to the first card.

So far so good. Probel is the example cdoe I have passes _NO_ arguments to
the new call. Any idea what the first one should be?
 
J

Jeff 'japhy' Pinyan

[posted & mailed]

I'm trying to use the Video::Capture module (which has no docs) to capture
images from multple cards. I've finally found the following snippet of
code in the perl module itself:

sub new(;$) {
my $class = shift;
my $device = shift || "/dev/video0";
my $self = bless { device => $device }, $class;
}

It looks like the devie needs to be passed as the 2nd argument to the new
call., and if a 2nd arg is not received it defaults to the first card.

So far so good. Probel is the example cdoe I have passes _NO_ arguments to
the new call. Any idea what the first one should be?

The first argument to any class method is the class name. Have you used
any object-oriented Perl code before?

my $object = Class->new($this, $that);

calls (more or less) the Class::new() function, with the arguments
('Class', $this, $that).

package Class;
sub new {
my $class = shift; # 'Class'
my @args = @_; # $this, $that
# ...
}

Therefore, you want to do:

my $video = Video::Capture->new($device_location);
 
A

A. Sinan Unur

I'm trying to use the Video::Capture module (which has no docs) to
capture images from multple cards. I've finally found the following
snippet of code in the perl module itself:

sub new(;$) {
my $class = shift;
my $device = shift || "/dev/video0";
my $self = bless { device => $device }, $class;


It looks like the devie needs to be passed as the 2nd argument to the
new call., and if a 2nd arg is not received it defaults to the first
card.

So far so good. Probel is the example cdoe I have passes _NO_
arguments to the new call. Any idea what the first one should be?

when you say

my $video = Video::Capture->new();

the new method is passed Video::Capture as the first argument.

Sinan.
 
S

Stan Brown

In said:
[posted & mailed]
The first argument to any class method is the class name. Have you used
any object-oriented Perl code before?

Only copy be example WO an undertanding of why. I;ve never looked at the
source of the modules I was using before. OK that's a bad thing, but at
leats I'm willing to admint it.
my $object = Class->new($this, $that);
calls (more or less) the Class::new() function, with the arguments
('Class', $this, $that).
package Class;
sub new {
my $class = shift; # 'Class'
my @args = @_; # $this, $that
# ...
}
Therefore, you want to do:
my $video = Video::Capture->new($device_location);

Ah, I see the things to the right of the -> are ALL arguments.

Rhanks, you have solved my imediate problem, AND educated me. Now I can go
fishing :) (references the famous saying about teaching to fish).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top