App-Widget

 view release on metacpan or  search on metacpan

lib/App/Widget.pm  view on Meta::CPAN

#    }
#
#    &App::sub_exit($handled) if ($App::trace);
#    return($handled);
#}

#############################################################################
# Method: content()
#############################################################################

=head2 content()

    * Signature: $content = $self->content();
    * Param:     void
    * Return:    $content   any
    * Throws:    App::Exception
    * Since:     0.01

    $content = $so->content();
    if (ref($content)) {
        App::Reference->print($content);
        print "\n";
    }
    else {
        print $content, "\n";
    }

=cut

sub content {
    &App::sub_entry if ($App::trace);
    my $self = shift;
    my ($html);

    eval {
        $html = $self->html();
    };
    if ($@) {
        my ($name, $msg);
        if (ref($@) eq "") {  # i.e. a string thrown with "die"
            $msg = $@;
        }
        elsif ($@->isa("App::Exception")) {
            $msg = $@->error . "\n" . $@->trace->as_string . "\n";
        }
        else {
            $@->rethrow();
        }
        $msg =~ s{&}{&}gso;
        $msg =~ s{<}{&lt;}gso;
        $msg =~ s{>}{&gt;}gso;
        $msg =~ s{\"}{&quot;}gso;
        $msg =~ s{\n}{<br>\n}gso;
        $name = $self->{name};
        $html = <<EOF;
<table border="1" cellspacing="0">
<tr><td bgcolor="#aaaaaa">
<b>Widget Display Error: $name</b><br>
</td></tr>
<tr><td bgcolor="#ffaaaa">
<font size="-1" face="sans-serif">
$msg
</font>
</td></tr>
</table>
EOF
    }

    if (defined $self->{content}) {
        my $content = $self->{content};
        $self->{content} = "";
        &App::sub_exit($content) if ($App::trace);
        return($content);
    }

    my ($title, $bodyoptions, $w, $var, $value);

    $title = "Widget";
    $bodyoptions = "";
    if (ref($self)) {
        $title = $self->get("title");
        $title = $self->get("name") if (!$title);
        foreach $var ('bgcolor', 'text', 'link', 'vlink', 'alink',
                      'leftmargin', 'topmargin', 'rightmargin', 'bottommargin') {
            $value = $self->get($var);
            if (defined $value && $value ne "") {
                $bodyoptions .= " $var=\"$value\"";
            }
            elsif ($var eq "bgcolor") {
                $bodyoptions .= " $var=\"#ffffff\"";
            }
        }
    }
    $bodyoptions .= " onLoad=\"$self->{onload_handler}\"" if ($self->{onload_handler});

    my $context = $self->{context};
    my $options = $context->{options};
    my $response = $context->response();
    my $context_head = $options->{"app.html.head"} || "";
    my $context_body = "";
    if ($response->{include}{css_list}) {
        my $items = $response->{include}{css_list};
        foreach my $item (@$items) {
            if ($item =~ /^</) {
                $context_head .= $item;
            }
            else {
                $context_head .= "<link href=\"$item\" type=\"text/css\" rel=\"stylesheet\">\n";
            }
        }
    }
    if ($response->{include}{javascript}) {
        my $items = $response->{include}{javascript_list};
        foreach my $item (@$items) {
            if ($item =~ /^</) {
                $context_head .= $item;
            }
            else {
                $context_head .= "<script src=\"$item\" type=\"text/javascript\" language=\"JavaScript\"></script>\n";
            }
        }
    }



( run in 0.908 second using v1.01-cache-2.11-cpan-5735350b133 )