📄 repeatrecord.pm
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
# Name : ETL::Pequel3::Type::Section::RepeatRecord.pm
# Created : 22 June 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::Section::RepeatRecord;
require 5.005_62;
use strict;
use warnings;
use ETL::Pequel3::Type::Section;
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::RepeatRecord::Abstract;
use base qw(ETL::Pequel3::Type::Section::Abstract);
use Class::STL::ClassMembers qw( fields ),
Class::STL::ClassMembers::DataMember->new(name => 'target_mem_name', default => 'section_name'),
Class::STL::ClassMembers::DataMember->new(name => 'item_type', default => 'ETL::Pequel3::Type::Section::RepeatRecord::Item'),
Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}");
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->fields($self->pequel_ref()->catalogue()->fieldsets()->repeat_expressions()->new(
pequel_ref => $self->pequel_ref()))
if (defined($self->pequel_ref()));
}
sub prepare
{
my $self = shift;
foreach ($self->items()->to_array()) {
$self->fields()->add(
name => "@{[ $self->section_name() ]}_@{[ $self->fields()->size()+1 ]}",
exp => $_->repeat_exp()
);
$self->err()->trace_msg(10, "@{[ $self->pequel_ref()->pequel_name() ]} -->"
. $self->section_name() . ':'
. $self->fields()->back()->exp()
);
}
}
package ETL::Pequel3::Type::Section::RepeatRecord::Item;
use base qw(ETL::Pequel3::Type::Section::Item::Abstract);
use Class::STL::ClassMembers;
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->attributes()->push_back(
$self->attributes()->factory(name => 'repeat_exp', required => 1),
);
}
}
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::RepeatRecord;
use base qw(ETL::Pequel3::Type::Section::RepeatRecord::Abstract);
use Class::STL::ClassMembers
Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'repeat_record'),
Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
Class::STL::ClassMembers::DataMember->new(name => 'description', default => 'This section is used to specify a record repeat action. Please refer to the specific F<repeat_record_on_input> and F<repeat_record_on_output> section type descriptions for detailed information.');
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->attributes()->push_back(
ETL::Pequel3::Type::Properties::On->new(),
);
return $self;
}
sub select
{
my $self = shift;
my %p = @_;
$self->err()->user_error(10211, "Section '@{[
$self->section_name() ]}' select() function requires 'on' parameter!")
unless (exists($p{on}));
return $self->pequel_ref()->section("@{[ $self->section_name() ]}_on_@{[ lc($p{on}) ]}")->select(@_);
}
}
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::RepeatRecordOnInput;
use base qw(ETL::Pequel3::Type::Section::RepeatRecord::Abstract);
use Class::STL::ClassMembers
Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'repeat_record_on_input'),
Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record repeat action. This action will cause the input record to be repeated according to the F<repeat_exp>. The F<repeat_exp> should evaluate to a range of values. The I<repeat> will occur for each of these values. The current I<repeat value> can be accessed by the C<&irval()> macro. The single argument to the C<&irval()> macro identifies the repeat number, starting from C<1> for the first item. Each F<item> defines a repeat action with the first item defining the outermost repeat within multiple nested repeats.\n\n\nThe F<repeat_record_on_input> actions will occur right after the I<input joins> actions.");
use Class::STL::ClassMembers::Constructor;
sub parse
{
my $self = shift;
foreach ($self->fields()->to_array()) {
$_->exp_raw($self->pequel_ref()->parser_input()->used_by($_)->translate($_->exp())->raw());
}
}
}
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::RepeatRecordOnOutput;
use base qw(ETL::Pequel3::Type::Section::RepeatRecord::Abstract);
use Class::STL::ClassMembers
Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'repeat_record_on_output'),
Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record repeat action. This action will cause the output record to be repeated according to the F<repeat_exp>. The F<repeat_exp> should evaluate to a range of values. The I<repeat> will occur for each of these values. The current I<repeat value> can be accessed by the C<&orval()> macro. The single argument to the C<&orval()> macro identifies the repeat number, starting from C<1> for the first item. Each F<item> defines a repeat action with the first item defining the outermost repeat within multiple nested repeats.\n\n\nThe output repeat actions will occur before the F<filter_on_output> and before the F<dedup_on_output> actions.");
use Class::STL::ClassMembers::Constructor;
sub parse
{
my $self = shift;
foreach ($self->fields()->to_array()) {
$_->exp_raw($self->pequel_ref()->parser_output()->used_by($_)->translate($_->exp())->raw());
}
}
}
# ----------------------------------------------------------------------------------------------------
1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -