NAME
    Schema::Abstract - Abstract class for DB schemas.

SYNOPSIS
     package Schema::Foo;
     use base qw(Schema::Abstract);

     sub _versions_file {
             return 'versions.txt';
     }

     package main;

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

DESCRIPTION
    This is abstract class for versioned schemas modules.

METHODS
  "new"
     my $obj = Schema::Abstract->new(%params);

    Constructor.

    *       "version"

            Selected schema version.

            Default value is last version.

    Returns instance of object.

  "list_versions"
     my @versions = $obj->list_versions;

    Get sorted list of versions.

    Returns array of versions.

  "schema"
     my $schema = $obj->schema;

    Get schema module name.

    Returns string.

  "version"
     my $version = $obj->version;

    Get version of schema, which is actial set.

    Returns string.

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

             (only in this abstract class)
             We need to implement distribution file with Schema 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', 'Foo'));

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

     use base qw(Schema::Abstract);

     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', 'Foo', '0_1_0.pm');
     barf($package_schema_foo_0_1_0, <<'END');
     package Schema::Foo::0_1_0;

     1;
     END

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

     1;
     END

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

     1;
     END

     unshift @INC, $temp_dir;

     require Schema::Foo;

     my $obj = Schema::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-Abstract>

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

    <http://skim.cz>

LICENSE AND COPYRIGHT
    © 2022-2024 Michal Josef Špaček

    BSD 2-Clause License

VERSION
    0.05