XML-ExtOn

 view release on metacpan or  search on metacpan

lib/XML/ExtOn/Element.pm  view on Meta::CPAN

    $self->_context( $attr{context} ) or die "not exists context parameter";
    my $name = $attr{name};
    $self->attributes(
        new XML::ExtOn::Attributes::
          context => $self->_context,
        sax2 => exists $attr{sax2} ? $attr{sax2}->{Attributes} : {}
    );

    if ( my $sax2 = $attr{sax2} ) {
        $name ||= $sax2->{Name};
        my $prefix = $sax2->{Prefix} || '';
        $self->set_prefix(  );
        $self->set_ns_uri( $self->ns->get_uri( $prefix ) );
    }
    $self->_stack([]);
    $self->_wrap_around_start([]);
    $self->_wrap_around_end([]);
    $self->_wrap_begin([]);
    $self->_wrap_end([]);
    $self->_set_name($name);
    return $self;
}

sub __clone1 {
    my $self = shift;
    my $class = ref( $self);
    my %hash = %$self;
    my $selfc = bless \%hash, $class;
    $selfc->_wrap_end([]);
    $selfc->_wrap_begin([]);
    return $selfc;
}

sub __clone {
    my $self = shift;
    my $class = ref( $self);
    my %hash = ();
    use Tie::UnionHash;
    tie %hash, 'Tie::UnionHash', $self, {};
    my $selfc = bless \%hash, $class;
    $selfc->_wrap_end([]);
    $selfc->_wrap_begin([]);
    $selfc->_wrap_around_start([]);
    $selfc->_wrap_around_end([]);
    $selfc->_stack([]);
    return $selfc;
}


sub _set_name {
    my $self = shift;
    $self->{__name} = shift || return $self->{__name};
}

=head2 add_content <element object1>[, <element object2> ...]

Add commands to contents stack.Return C<$self>

    $elem->add_content( 
        $self->mk_from_xml("<p/>"),
        $self->mk_cdata("TEST CDATA"),
        )

=cut

sub add_content {
    my $self = shift;
    push @{$self->_stack()}, @_;
    return $self
}

=head2 insert_to <element object>

Wrap by C<element object>.Return C<$self>

    $elem->insert_to( $self->mk_element('wrap') )

=cut

sub insert_to {
    my $self = shift;
    if ( @_ ) {
        push @{$self->_wrap_begin()}, @_;
        push @{$self->_wrap_end()}, @_
    }
    return $self
}

=head2 wrap_around (element object)

Wrap around  C<element object>.Return C<$self>

=cut

sub wrap_around {
    my $self= shift;
    if ( @_ ) {
        push @{$self->_wrap_around_start()}, @_;
        push @{$self->_wrap_around_end()}, @_
    }
    $self
}

=head2 mk_element <tag name>

Create element object  in namespace of element.

=cut

sub mk_element {
    my $self = shift;
    my $name = shift;
    my %args = @_;
    $args{context} ||= $self->ns->sub_context();
    my $elem = new XML::ExtOn::Element::
      name => $name,
      %args;
    return $elem;
}

sub set_prefix {



( run in 2.212 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )