The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Software::Packager::Object - Generic object data storage

SYNOPSIS

use Software::Packager::Object;

DESCRIPTION

This module is used by Software::Packager for holding data for a each item added to the a software package. It provides an easy way of accessing the data for each object to be installed. This module is designed to be easly sub classed and / or extended.

SUB-CLASSING

To extend or sub-class this module create a new module along the lines of

 package Foo;

 use Software::Packager::Object;
 use vars qw(@ISA);
 @ISA = qw( Software::Packager::Object );

 ########################
 # _check_data we don't care about anything other that DESTINATION and FOO_DATA;
 sub _check_data
 {
        my $self = shift;
        my %data = @_;

        return undef unless $self->{'DESTINATION'};
        return undef unless $self->{'FOO_DATA'};

        # now set the data for the object
        foreach my $key (keys %data)
        {
                my $function = lc $key;
                return undef unless $self->$function($data{$key});
        }
 }

 ########################
 # foo_data returns the foo value fo this object.
 sub foo_data
 {
        my $self = shift;
        return $self->{'FOO_DATA'};
 }
 1;
 __END__

Of course I would have created the module with a package of Software::Packager::Object::Foo but that's you choice.

FUNCTIONS

new()

 my $object = new Software::Packager::Object(%object_data);

This function creates and returns a new Software::Packager::Object object which is used to access the data in the passed hash. This passed data is passed on and checked for problems by the _check_data() method.

The hash of data passed should contain at least the following

 %hash = (
        'TYPE' => 'file type',
        'SOURCE' => 'source file location. Not required for directories.',
        'DESTINATION' => 'destination location',
        'USER' => 'user to install as',
        'GROUP' => 'group to install as',
        'MODE' => 'permissions to install the file with',
        );

_check_data()

 $self->_check_data(%data);

This function checks that the data for this object is okay and returns true if there are problems with the data then undef is returned.

 TYPE           If the type is a file then the value of SOURCE must be a real
                file. If the type is a soft/hard link then the source and
                destination must both be present.
 SOURCE         nothing special to check, see TYPE
 DESTINATION    nothing special to check, see TYPE
 MODE           Defaults to 0755 for directories and 0644 for files.
 USER           Defaults to the current user
 GROUP          Defaults to the current users primary group

type()

 $object->type($value);
 $type = $object->type();

This method sets or returns the type of this object. When the object type is being set then the value passed will be checked.

Valid object types are:

 File:       A standard file.
 Directory:  A directory.
 Hardlink:   A file link.
 Softlink:   A symbolic link.
 Install:    An installation file used by the installer.
 Config:     A configuration file.
 Volatile:   A volatile file.
 Pipe:       A named pipe.
 Charater:   A charater special device.
 Block:      A block special device.
 Multiplex:  A multiplexed special device.

source()

 $object->source($value);
 $source = $object->source();

This method sets or returns the source location for this object.

destination()

 $object->destination($value);
 $destination = $object->destination();

This method sets or returns the destination location for this object.

mode()

 $object->mode($value);
 $mode = $object->mode();

This method sets or returns the installation mode for this object.

NOTE: The mode is stored in octal but that doesn't mean that you are using it in octal if you are trying to use the return value in a chmod command then do something like.

 $mode = oct($object->mode());
 chmod($mode, $object->destination());

Do lots of tests!

If the mode is not set then default values are set. Directories are set to 0755 everything else defaults to the mode the object source has.

user()

 $object->user($value);
 $user = $object->user();

This method sets or returns the user id that this object should be installed as. If the user is not set for the object then the user defaults to the current user.

If this becomes a problem it can be changed to be the owner of the object.

group()

This method sets or returns the group id that this object should be installed as. If the group is not set for the object then the group defaults to the current primary group.

If this becomes a problem it can be changed to be the group of the object.

SEE ALSO

 Software::Packager

AUTHOR

 R Bernard Davison <rbdavison@cpan.org>
 If you extend this module I'd really like to see what you do with it. 

COPYRIGHT

 Copyright (c) 2001 Gondwanatech. All rights reserved.
 This program is free software; you can redistribute it and/or modify it under
 the same terms as Perl itself.