⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 field.pm

📁 普通的ETL工具
💻 PM
📖 第 1 页 / 共 2 页
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
#  Name		: ETL::Pequel3::Type::Field.pm
#  Created	: 19 December 2006
#  Author	: Mario Gaffiero (gaffie)
#
# Copyright 1999-2007 Mario Gaffiero.
# 
# This file is part of Pequel(TM).
# 
# Pequel is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# Pequel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Pequel; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ----------------------------------------------------------------------------------------------------
# Modification History
# When          Version     Who     What
# ----------------------------------------------------------------------------------------------------
package ETL::Pequel3::Type::Field;
require 5.005_62;
use strict;
use warnings;
use stl;
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Field::Abstract;
	use base qw(Class::STL::Element);
	use Class::STL::ClassMembers 
		qw( 
			err
			name 
			description
			field_number 
			tname 
			configuration 
			used_by_list 
			use_list 
			pequel_types 
			date_types 
			aggregate_types
			catalogue
			xref
			pequel_ref
		),
		Class::STL::ClassMembers::DataMember->new(
			name => 'xml_type', default => 'PCDATA', validate => '^(attr|PCDATA|CDATA)$');
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->err(ETL::Pequel3::Error->new());
		$self->catalogue(ETL::Pequel3::Catalogue->new());
		$self->err()->user_error(10221, "Attribute @{[ __PACKAGE__ ]}::pequel_ref is undefined!")
			unless (defined($self->pequel_ref()));
		defined($self->pequel_ref()->config())
			? $self->configuration($self->pequel_ref()->config())
			: $self->configuration(ETL::Pequel3::Type::Properties::User->new());
		$self->used_by_list(stl::list());#TODO:remove
		$self->use_list(stl::list());#TODO:remove
		$self->data($self->name());
		$self->pequel_types(ETL::Pequel3::Type::PequelTypes::Catalogue->new());
		$self->date_types(ETL::Pequel3::Type::Dates::Catalogue->new());
		use ETL::Pequel3::CrossRef;
		$self->xref(ETL::Pequel3::CrossRef->new(
#?			xref_key =>... # instead of passing 
#?			(
#?				$self->pequel_ref()->pequel_name()
#?				. '::'
#?				. (split(/[:]+/, ref($self)))[-1] 
#?				. '::'
#?				. $self->name()
#?			),
			target_obj => $self, 
			target_name => $self->name(), 
			pequel_ref => $self->pequel_ref(),
			@_,
		)) unless (defined($self->xref()));
		return $self;
	}
	sub getvar
	{
		# virtual function
	}
	sub print_info
	{
		my $self = shift;
		return "@{[ $self->pequel_ref()->pequel_name() ]} -->"
			. ( (split(/[:]+/, ref($self)))[-1] ) . ' -- ' . $self->name()
			. "[" 
			. ($self->can('ds_column') && defined($self->ds_column()) ? $self->ds_column() : 'n/a')
				. ":" . $self->field_number() . "]"
			. ($self->can('pequel_type') && defined($self->pequel_type()) 
				? " -- @{[ ref($self->pequel_type()) ? $self->pequel_type()->name() : $self->pequel_type() ]}" : '')
			. ($self->can('date_type') && defined($self->date_type()) 
				? " -- date_type: @{[ ref($self->date_type()) ? $self->date_type()->name() : $self->date_type() ]}" : '')
			. ($self->can('input_field') && defined($self->input_field()) 
				? " -- input_field: @{[ $self->input_field()->name() ]}" : '')
			. ($self->can('output_field') && defined($self->output_field()) 
				? " -- output_field: @{[ $self->output_field()->name() ]}" : '')
			. ($self->can('calc_exp') && defined($self->calc_exp()) ? ' -- derived' : '')
			. ($self->can('condition_exp') && defined($self->condition_exp()) ? "(conditional)" : '')
			. ($self->can('aggregate_type') && defined($self->aggregate_type()) 
				? " -- aggregate @{[ $self->aggregate_type()->name() ]}" : '')
			. (defined($self->xml_type()) ? " -- xml_type @{[ $self->xml_type() ]}" : '')
		;
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Field::InputField;
	use base qw(ETL::Pequel3::Type::Field::Abstract);
	use Class::STL::ClassMembers qw( calc_exp calc_exp_raw dataset date_type pequel_type operator ),
		Class::STL::ClassMembers::DataMember->new(name => 'pequel_type', default => 'string');
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->tname('_I_' . $self->name());

		if (defined($self->pequel_type()) && !ref($self->pequel_type())) {
			my $pequel_type = $self->pequel_types()->exists($self->pequel_type())
				|| $self->err()->user_error(10219, "Unkown pequel-type '@{[ 
					$self->pequel_type() ]}' for input field '@{[ $self->name() ]}'");
			$self->pequel_type($pequel_type);
		}

		$self->date_type($self->date_types()->exists($self->configuration()->default_datetype())) 
			if ($self->pequel_type()->name() eq 'date' && !defined($self->date_type()));
		return $self;
	}
	sub getvar
	{
		my $self = shift;
		return "\$@{[ $self->dataset()->arr_vname() ]}\[" 
			. (
				$self->configuration()->show_synonyms()
					? "\$c@{[ $self->tname() ]}"
					: $self->field_number() -1
				)
			. ']';
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Field::OutputField;
	use base qw(ETL::Pequel3::Type::Field::Abstract);
	use Class::STL::ClassMembers 
		qw( 
			date_type 
			aggregate_type 
			input_field 
			condition_exp 
			condition_exp_raw
			calc_exp 
			calc_exp_raw
			dataset 
		),
#>TODO: condition_exp should be attribute of aggregate ??
		Class::STL::ClassMembers::DataMember->new(
			name => 'pequel_type', default => 'string'),
		Class::STL::ClassMembers::DataMember->new(
			name => 'serial_start', default => 0); #TODO should be an attribute of the aggregate
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->tname('_O_' . $self->name());

		#TODO: incorrect: input_field should only contain a reference to actual input-field;
		$self->input_field(ETL::Pequel3::Type::Field::InputField->new(
			name => $self->input_field(),
			pequel_ref => $self->pequel_ref()
		))
		if (defined($self->input_field()) && !ref($self->input_field()));
		$self->input_field()->xref()->referenced_by($self) if (defined($self->input_field()));
		$self->xref()->references($self->input_field()) if (defined($self->input_field()));

		if (defined($self->pequel_type()) && !ref($self->pequel_type())) {
			my $pequel_type = $self->pequel_types()->exists($self->pequel_type())
				|| $self->err()->user_error(10219, "Unkown pequel-type '@{[ 
					$self->pequel_type() ]}' for output field '@{[ $self->name() ]}'");
			$self->pequel_type($pequel_type);
		}
		if (defined($self->pequel_type()) && $self->pequel_type()->name() eq 'date') {
			my $typename = $self->date_type() || $self->configuration()->default_datetype();
			my $type;
			$self->err()->user_error(10217, "Unknown date type '$typename' for output field '@{[ $self->name() ]}'!")
				unless ($type = $self->date_types()->exists($typename));
			$self->date_type($type);
		}
		if (defined($self->aggregate_type()) && !ref($self->aggregate_type())) {
			my $aggregate_type = $self->catalogue()->aggregates()->exists($self->aggregate_type())
				|| $self->err()->user_error(10220, "Unknown aggregate type '@{[ 
					$self->aggregate_type() ]}' for output field '@{[ $self->name() ]}'");
			$self->aggregate_type($aggregate_type->new(
					output_field => $self,
#>TODO				condition_exp => $self->condition_exp(),
#>					serial_start => $self->serial_start(),
					pequel_ref => $self->pequel_ref(),
				));
			#TODO: check pequel-type for aggregate...
		}
		if (defined($self->aggregate_type())) {
			$self->aggregate_type()->xref()->referenced_by($self);
			$self->xref()->references($self->aggregate_type());
		}
		#TODO: condition_exp should be attr of aggregate...
		$self->condition_exp(do { my $c = $self->condition_exp(); $c =~ s/^\s*where\s+//i; $c; })
			if (defined($self->condition_exp()));
		return $self;
	}
	sub getvar
	{
		my $self = shift;
		return 
			(
				$self->configuration()->hash()
					? "\$@{[ $self->dataset()->arr_vname() ]}\{\$_HKEY}{" 
					: "\$@{[ $self->dataset()->arr_vname() ]}\[" 
			)
			.
			(
				$self->configuration()->show_synonyms()
					? "\$c@{[ $self->tname() ]}"
					: $self->field_number() -1
			) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -