Alzabo

 view release on metacpan or  search on metacpan

lib/Alzabo/BackCompat.pm  view on Meta::CPAN

package Alzabo::BackCompat;

use strict;

use Alzabo::Config;

use File::Basename;
use File::Copy;
use File::Spec;
use Storable;
use Tie::IxHash;

use Params::Validate qw( :all );
Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } );

use vars qw($VERSION);

$VERSION = 2.0;

#
# Each pair represents a range of versions which are compatible with
# each other.  The first one is not quite right but it has to start
# somewhere ;)
#
# Any extra elements are subroutines which should be run to update the
# schema, if it's version is lower than the first element of the
# version pair.
#
my @compat = ( [ 0, 0.64 ],
               [ 0.65, 0.70,
                 \&add_comment_fields,
               ],
               [ 0.71, 0.73,
                 \&convert_pk_to_array,
               ],
               [ 0.79, $Alzabo::VERSION,
                 \&add_table_attributes,
               ],
             );

sub update_schema
{
    my %p = validate( @_, { name    => { type => SCALAR },
                            version => { type => SCALAR },
                          } );

    my @cb;
    foreach my $c (@compat)
    {
        return
            if ( ( $p{version} >= $c->[0] &&
                   $p{version} <= $c->[1] ) &&

                 ( $Alzabo::VERSION >= $c->[0] &&
                   $Alzabo::VERSION <= $c->[1] )
               );

        if ( $p{version} < $c->[0] && @$c > 2 )
        {
            push @cb, @{$c}[2..$#$c];
        }
    }

    my $create_loaded;
    unless ( $Alzabo::Create::Schema::VERSION )
    {
        require Alzabo::Create::Schema;
        $create_loaded = 1;
    }

    my $v = $p{version} = 0 ? '0.64 or earlier' : $p{version};

    my $c_file = Alzabo::Create::Schema->_schema_filename( $p{name} );
    unless ( -w $c_file )
    {
        my $msg = <<"EOF";

The '$p{name}' schema was created by an older version of Alzabo
($v) than the one currently installed ($Alzabo::VERSION).

Alzabo can update your schema objects but your schema file:

  $c_file

is not writeable by this process.  Loading this schema in a process
which can write to this file will cause the schema to be updated.

EOF

        die $msg;
    }

    my $dir = dirname($c_file);
    unless ( -w $dir )
    {
        my $msg = <<"EOF";

The '$p{name}' schema was created by an older version of Alzabo
($v) than the one currently installed ($Alzabo::VERSION).

Alzabo can update your schema objects but its director:

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.208 second using v1.00-cache-2.02-grep-82fe00e-cpan-1310916c57ae )