Ambrosia
view release on metacpan or search on metacpan
share/Managers/buildXml.pm view on Meta::CPAN
package Managers::buildXml;
use strict;
use warnings;
use Cwd qw/abs_path/;
use Ambrosia::Config;
use Ambrosia::error::Exceptions;
use Ambrosia::DataProvider;
use Ambrosia::Context;
use Ambrosia::Meta;
class sealed
{
extends => [qw/Ambrosia::BaseManager/],
private => [qw/__tableIdInc/],
};
our $VERSION = 0.010;
sub _init
{
$_[0]->__tableIdInc = 1;
}
sub prepare
{
my $self = shift;
Context->repository->set( schema_list => [] );
storage->foreach(\&processDataSource, $self);
my $path_to_app = config->ProjectPath;
if ( $path_to_app )
{
$path_to_app =~ s{/[^/]+$}{};
}
else
{
$path_to_app = '';
}
my $projectName = config()->ID;
my $message = <<MESSAGE;
#######################################################################
#
# ADL file ${projectName}.xml has been created successfully.
#
# Now you can additionally edit ${projectName}.xml and run:
# ambrosia -c ${projectName}.conf -d ${projectName}.xml -a xml2app
#
#######################################################################
MESSAGE
chomp(my $hostname = `hostname`);
Context->repository->set( config => {
name => config->ID,
label => config->Label,
charset => lc(config->Charset || 'utf-8'),
hostname => config->hostname || $hostname,
ServerName => config->ServerName,
ServerPort => config->ServerPort,
ProjectPath => abs_path($path_to_app),
PerlLibPath => join(' ', map {abs_path($_)} split /\s+/, config->PerlLibPath),
} );
Context->repository->set( Message => $message );
}
sub getDataSource
{
my $t = shift;
my $sn = shift;
if ( ref config->data_source->{$t} eq 'ARRAY' )
{
foreach ( @{config->data_source->{$t}} )
{
return $_ if $_->{source_name} eq $sn;
}
throw Ambrosia::error::Exception::BadParams "Error: cannot find in config data_source source_name=$sn in type = $t";
}
elsif( config->data_source->{$t}->{source_name} eq $sn )
{
return config->data_source->{$t};
}
else
{
throw Ambrosia::error::Exception::BadParams "Error: cannot find in config data_source source_name=$sn in type = $t";
}
}
sub processDataSource
{
my $driver = shift;
my $type = shift;
my $source_name = shift;
my $self = shift;
my $schema_list = Context->repository->get( 'schema_list' );
my $schema = {type => $type,
($driver->catalog ? (catalog => $driver->catalog) : ()),
schema => $driver->schema,
tables => [],
config => {} };
push @$schema_list, $schema;
my $ds = getDataSource($type, $source_name);
( run in 0.741 second using v1.01-cache-2.11-cpan-97f6503c9c8 )