package Prty::ContentProcessor::SubType;
use base qw/Prty::ContentProcessor::BaseType/;

use strict;
use warnings;

our $VERSION = 1.111;

# -----------------------------------------------------------------------------

=encoding utf8

=head1 NAME

Prty::ContentProcessor::SubType - Basisklasse für Sub-Typen

=head1 BASE CLASS

L<Prty::ContentProcessor::BaseType>

=head1 METHODS

=head2 Erzeugung

=head3 create() - Wandele Abschnitts-Objekt in Subtyp-Objekt

=head4 Synopsis

    $sty = $class->create($sec,$parent);

=head4 Description

Erweitere Abschnitts-Objekt $sec und blesse es zu einem Subtyp-Objekt.

=head4 Arguments

=over 4

=item $sec

Referenz auf Abschnitts-Objekt.

=item $parent

Referenz auf übergeordnetes (Sub)Typ-Objekt.

=back

=head4 Returns

Zum Subtyp geblesstes Abschnitts-Objekt.

=cut

# -----------------------------------------------------------------------------

sub create {
    my ($class,$sec,$parent) = splice @_,0,3;
    # @_: @keyVal

    # Inhalt und Abschnitts-Attribute prüfen
    $sec->validate($class->contentAllowed,scalar $class->attributes);
        
    $sec->set(
        parent=>$parent,
        # memoize
        name=>undef,
        # Subklassen-Attribute
        @_,
    );
    $sec->weaken('parent');
    
    return bless $sec,$class;
}

# -----------------------------------------------------------------------------

=head2 Intern

=head3 name() - Name der Sub-Entitt

=head4 Synopsis

    $name = $sty->name;

=head4 Description

Liefere den Namen der Sub-Entität. Dies ist der Wert
des Attributs C<Name:>, bereinigt um Besonderheiten:

=over 2

=item *

ein Sigil am Namensanfang (z.B. C<°°>) wird entfernt

=back

=cut

# -----------------------------------------------------------------------------

sub name {
    my $self = shift;

    return $self->memoize('name',sub {
        my ($self,$key) = @_;
        
        my ($name) = $self->get('Name');
        if (!$name) {
            $self->throw;
        }
        $name =~ s/^\W+//; # Sigil entfernen

        return $name;
    });
}

# -----------------------------------------------------------------------------

=head1 VERSION

1.111

=head1 AUTHOR

Frank Seitz, L<http://fseitz.de/>

=head1 COPYRIGHT

Copyright (C) 2017 Frank Seitz

=head1 LICENSE

This code is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

# -----------------------------------------------------------------------------

1;

# eof
