Youri::Media - Abstract media class


Youri-Media documentation Contained in the Youri-Media distribution.

Index


Code Index:

NAME

Top

Youri::Media - Abstract media class

DESCRIPTION

Top

This abstract class defines Youri::Media interface.

CLASS METHODS

Top

new(%args)

Creates and returns a new Youri::Media object.

Generic parameters:

id $id

Media id.

name $name

Media name.

type $type (source/binary)

Media type.

test true/false

Test mode (default: false).

verbose true/false

Verbose mode (default: false).

options $options

Hash of test-specific options.

skip_tests $tests

List of tests to skip.

skip_archs $arches

List of arches to skip.

Subclass may define additional parameters.

Warning: do not call directly, call subclass constructor instead.

INSTANCE METHODS

Top

get_id()

Returns media identity.

get_name()

Returns the name of this media.

get_type()

Returns the type of this media.

get_option($test, $option)

Returns a specific option for given test.

skip_archs()

Returns the list of arch which are to be skipped for this media.

skip_arch($arch)

Tells wether given arch is to be skipped for this media.

skip_tests()

Returns the list of id of test which are to be skipped for this media.

skip_test($test_id)

Tells wether test with given id is to be skipped for this media.

get_package_class()

Return package class for this media.

traverse_files($function)

Apply given function to all files of this media.

traverse_headers($function)

Apply given function to all headers, partially parsed, of this media.

traverse_full_headers($function)

Apply given function to all headers, fully parsed, of this media.

SUBCLASSING

Top

The following methods have to be implemented:

traverse_headers
traverse_full_headers
traverse_files

COPYRIGHT AND LICENSE

Top


Youri-Media documentation Contained in the Youri-Media distribution.
# $Id: /mirror/youri/soft/Media/trunk/lib/Youri/Media.pm 2367 2007-04-22T18:47:34.552172Z guillomovitch  $
package Youri::Media;

use Carp;
use strict;
use warnings;
use version; our $VERSION = qv('0.2.1');

sub new {
    my $class = shift;
    croak "Abstract class" if $class eq __PACKAGE__;

    my %options = (
        name           => '',    # media name
        canonical_name => '',    # media canonical name
        type           => '',    # media type
        test           => 0,     # test mode
        verbose        => 0,     # verbose mode
        options        => undef,
        @_
    );


    croak "No type given" unless $options{type};
    croak "Wrong value for type: $options{type}"
        unless $options{type} =~ /^(?:binary|source)$/;

    # some options need to be arrays. Check it and convert to hashes
    foreach my $option (qw(skip_archs skip_tests)) {
        next unless defined $options{$option};
        croak "$option should be an arrayref"
            unless ref $options{$option} eq 'ARRAY';
        $options{$option}  = {
            map { $_ => 1 } @{$options{$option}}
        };
    }

    croak "options should be an hashref"
        if $options{options} && ref $options{options} ne 'HASH';

    my $self = bless {
        _id         => $options{id}, 
        _verbose    => $options{verbose}, 
        _name       => $options{name} || $options{id}, 
        _type       => $options{type}, 
        _options    => $options{options}, 
        _skip_archs => $options{skip_archs},
        _skip_tests => $options{skip_tests},
    }, $class;

    $self->_init(%options);

    # remove unwanted archs
    if ($options{skip_archs}->{all}) {
        $self->_remove_all_archs()
    } elsif ($options{skip_archs}) {
        $self->_remove_archs($options{skip_archs});
    }

    return $self;
}

sub _init {
    # do nothing
}

sub get_id {
    my ($self) = @_;
    croak "Not a class method" unless ref $self;

    return $self->{_id};
}

sub get_name {
    my ($self) = @_;
    croak "Not a class method" unless ref $self;

    return $self->{_name};
}

sub get_type {
    my ($self) = @_;
    croak "Not a class method" unless ref $self;

    return $self->{_type};
}

sub get_option {
    my ($self, $test, $option) = @_;
    croak "Not a class method" unless ref $self;

    return $self->{_options}->{$test}->{$option};
}

sub skip_archs {
    my ($self) = @_;
    croak "Not a class method" unless ref $self;

    return keys %{$self->{_skip_archs}};
}

sub skip_arch {
    my ($self, $arch) = @_;
    croak "Not a class method" unless ref $self;

    return
        $self->{_skip_archs}->{all} ||
        $self->{_skip_archs}->{$arch};
}

sub skip_tests {
    my ($self) = @_;
    croak "Not a class method" unless ref $self;

    return keys %{$self->{_skip_tests}};
}

sub skip_test {
    my ($self, $test) = @_;
    croak "Not a class method" unless ref $self;

    return
        $self->{_skip_tests}->{all} ||
        $self->{_skip_tests}->{$test};
}

1;