Palm-Progect

 view release on metacpan or  search on metacpan

bin/progconv  view on Meta::CPAN

    if ($target_format ne 'auto' and !exists $converters{$target_format}) {
        die "Unrecognized output type: $target_format\n";
    }
    if ($target) {
        if ($target_format ne 'pdb' and !exists $converters{$target_format}) {
            # 'Auto'
            $target_format = $extension_converters{$target_extension};

            # Error if we can't determine the type
            if (!exists $converters{$target_format}) {
                die "Can't determine type from extension: $target_extension\n";
            }

        }
    }
    else { # Dump text to STDOUT if Target filename not specified
        $target_format = 'text' if $target_format eq 'auto';
    }
}


################################################################################
# Dispatch to the proper class to do the actual translations
#
# At this point, $source_converter and target converter will both
# be set to 'pdb' or to a Converter name
#

# Options passed to all modules start with the 'general' options
# (i.e. quiet, show-help, etc.)
my %General_Options = (
    quiet => $Options{'general'}{'quiet'},
);

my $progect_db = Palm::Progect->new(options => \%General_Options);

for my $version ($Options{'general'}{'input_version'}, $Options{'general'}{'input_version'}) {
    if ($version && !$handled_db_versions{$version}) {
        die "Can't handle Progect db version: $version\n";
    }
}

if ($source_format eq 'pdb') {
    $progect_db->load_db(
        file    => $source,
        version => $Options{'general'}{'input_version'},
    );
}
else {
    # Use proper, capitalized names for converters
    my $source_format_name = $converters{$source_format}{'Name'};

    # merge the options for this format into the options
    # we pass to the converter module

    my %Passed_Options = %General_Options;
    for (keys %{$Options{'converters'}{$source_format}}) {
        $Passed_Options{$_} = $Options{'converters'}{$source_format}{$_};
    }

    $progect_db->import_prefs(
        file    => $source,
        format  => $source_format_name,
        %Passed_Options,
    );
    $progect_db->import_records(
        file    => $source,
        format  => $source_format_name,
        %Passed_Options,
    );
}

if ($target_format eq 'pdb') {
    $progect_db->save_db(
        file    => $target,
        version => $Options{'general'}{'output_version'},
        %Options,
    );
}
else {
    # Use proper, capitalized names for converters
    my $target_format_name = $converters{$target_format}{'Name'};

    # # merge the options for this format into the options
    # we pass to the converter module

    my %Passed_Options = %General_Options;
    for (keys %{$Options{'converters'}{$target_format}}) {
        $Passed_Options{$_} = $Options{'converters'}{$target_format}{$_};
    }

    $progect_db->export_prefs(
        file    => $target,
        format  => $target_format_name,
        %Passed_Options,
    );
    $progect_db->export_records(
        file    => $target,
        format  => $target_format_name,
        %Passed_Options,
    );
}

# return info on each converter module that can be found

sub find_converters {
    local *DIR;

    my %converter;
    foreach my $inc (@INC) {
        my $path = File::Spec->join($inc, 'Palm', 'Progect', 'Converter');

        next unless -d $path;

        if (opendir DIR, $path) {
            my @modules = readdir(DIR);
            close DIR;

            foreach my $module (@modules) {
                next unless -f File::Spec->join($path, $module);
                next unless $module =~ /^(.*)\.pm$/;

                $converters{lc $1} = { Name => $1 };
            }
        }
    }

    foreach my $converter (keys %converters) {
        my $name = $converters{$converter}{Name};
        $converters{$converter}{Class} = 'Palm::Progect::Converter::' . $name;
        $converters{$converter}{File}  = File::Spec->join('Palm', 'Progect', 'Converter', $name . '.pm' );
    }

    return %converters if wantarray;
    return \%converters;
}

sub find_handled_db_versions {
    my @handled_versions;
    foreach my $inc (@INC) {
        my $path = File::Spec->join($inc, 'Palm', 'Progect');

        next unless -d $path;

        if (opendir DIR, $path) {
            my @subdirs = readdir(DIR);
            close DIR;

            foreach my $subdir (@subdirs) {
                next unless -d File::Spec->join($path, $subdir);

                next unless $subdir =~ /^DB_(\d*)$/;



( run in 1.164 second using v1.01-cache-2.11-cpan-5a3173703d6 )