NAME

Schema::Data - Abstract class for versioned DB schema datasets.

SYNOPSIS

package Schema::Data::Foo;
use base qw(Schema::Data);

sub _versions_file {
        return 'versions.txt';
}

package main;

my $obj = Schema::Data::Foo->new;
my @versions = $obj->list_versions;
my $schema_data = $obj->schema_data;
my $version = $obj->version;

DESCRIPTION

This is abstract class for versioned schema dataset modules.

METHODS

new

my $obj = Schema::Data->new(%params);

Constructor.

Returns instance of object.

  • version

    Selected schema data version.

    Default value is last version.

list_versions

my @versions = $obj->list_versions;

Get sorted list of versions.

Returns array of versions.

schema_data

my $schema_data = $obj->schema_data;

Get schema data module name.

Returns string.

version

my $version = $obj->version;

Get version of schema data, which is actial set.

Returns string.

ERRORS

new():
        Cannot load Schema data module.
                Module name: %s
                Error: %s
        Schema data version has bad format.
                Schema data version: %s
        From Class::Utils::set_params():
                Unknown parameter '%s'.

        (only in this abstract class)
        We need to implement distribution file with Schema data versions.

EXAMPLE

use strict;
use warnings;

use File::Path qw(make_path);
use File::Spec::Functions qw(catfile);
use File::Temp qw(tempdir tempfile);
use IO::Barf qw(barf);

# Temp directory for generated module
my $temp_dir = tempdir(CLEANUP => 1);

# File with versions.
my (undef, $versions_file) = tempfile();

make_path(catfile($temp_dir, 'Schema', 'Data', 'Foo'));

my $package_schema_foo = catfile($temp_dir, 'Schema', 'Data', 'Foo.pm');
barf($package_schema_foo, <<"END");
package Schema::Data::Foo;

use base qw(Schema::Data);

use IO::Barf qw(barf);

sub _versions_file {
        barf('$versions_file', "0.2.0\\n0.1.0\\n0.1.1");

        return '$versions_file';
}

1;
END

my $package_schema_foo_0_1_0 = catfile($temp_dir, 'Schema', 'Data', 'Foo', '0_1_0.pm');
barf($package_schema_foo_0_1_0, <<'END');
package Schema::Data::Foo::0_1_0;

1;
END

my $package_schema_foo_0_1_1 = catfile($temp_dir, 'Schema', 'Data', 'Foo', '0_1_1.pm');
barf($package_schema_foo_0_1_1, <<'END');
package Schema::Data::Foo::0_1_1;

1;
END

my $package_schema_foo_0_2_0 = catfile($temp_dir, 'Schema', 'Data', 'Foo', '0_2_0.pm');
barf($package_schema_foo_0_2_0, <<'END');
package Schema::Data::Foo::0_2_0;

1;
END

unshift @INC, $temp_dir;

require Schema::Data::Foo;

my $obj = Schema::Data::Foo->new;

my @versions = $obj->list_versions;

print join "\n", @versions;

unlink $versions_file;

# Output:
# 0.1.0
# 0.1.1
# 0.2.0

DEPENDENCIES

Class::Utils, English, Error::Pure, Perl6::Slurp.

REPOSITORY

https://github.com/michal-josef-spacek/Schema-Data

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2022-2023 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.06