Can someone explain this to me?

Discussion in 'Perl Misc' started by Stan Brown, Oct 31, 2003.

  1. Stan Brown

    Stan Brown Guest

    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?
     
    Stan Brown, Oct 31, 2003
    #1
    1. Advertisements

  2. [posted & mailed]

    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);
     
    Jeff 'japhy' Pinyan, Oct 31, 2003
    #2
    1. Advertisements

  3. when you say

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

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

    Sinan.
     
    A. Sinan Unur, Oct 31, 2003
    #3
  4. Stan Brown

    Stan Brown Guest

    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.
    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).
     
    Stan Brown, Oct 31, 2003
    #4
  5. Stan Brown

    Stan Brown Guest

    Ah, now I have an even better understanding of this.
     
    Stan Brown, Oct 31, 2003
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.