--- trunk/lib/Frey/Web.pm 2008/12/12 18:01:02 819 +++ trunk/lib/Frey/Web.pm 2008/12/14 22:47:48 839 @@ -174,35 +174,48 @@ } +sub _add_css_js { + my ( $self, $what, $content ) = @_; + + my $tag = $what eq 'css' ? 'style' : 'script'; + my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; + my $head; + + my ( $package, $path, $line ) = caller(1); + + if ( $content =~ m{\.(js|css)} ) { + $content = "/$content" if -e $content; + if ( $what eq 'js' ) { + $head = qq| + <$tag type="$type" src="$content"> + /* via $package at $path line $line */ + + |; + } else { + $head = qq| + + + |; + } + } else { + $head = qq| + <$tag type="$type"> + /* via $package at $path line $line */ + $content + + |; + }; + $self->add_head( $head ); +} + sub add_css { my ($self,$css) = @_; - my ( $package, $path, $line ) = caller; - $self->add_head( qq| - - | ); + $self->_add_css_js( 'css', $css ); } sub add_js { my ($self,$js) = @_; - my ( $package, $path, $line ) = caller; - - if ( $js =~ m{http.*\.js} ) { - $self->add_head( qq| - - |); - } else { - $self->add_head( qq| - - | ); - }; + $self->_add_css_js( 'js', $js ); } our $reload_counter = 0; @@ -246,10 +259,7 @@ if ( ! $body ) { my $run = $a->{run} || 'as_markup'; warn "# no body, invoke $self->$run on ", ref($self); - eval { - $body = $self->$run; - }; - $body = $self->error( $@, '' ) if $@; + $body = $self->$run; } if ( $self->content_type !~ m{html} ) { warn "# return only $self body ", $self->content_type; @@ -365,6 +375,13 @@ return $error; } +sub html_self { + my $self = shift; + my $html = $self; + $html =~ s{([\w:]+)=}{$1=}gsm; + return $html; +} + =head2 error This method will return error to browser and backtrace unless @@ -377,20 +394,22 @@ my $error = join(" ", @_); my $fatal = ''; + my $backtrace = ''; if ( $error !~ m{\n$} ) { if ( my @backtrace = $self->backtrace ) { - $error .= "\n\t" . join( "\n\t", @backtrace ); + $backtrace = + "\n" . $self->html_self . "->error backtrace\n\t" + . $self->html_links( join( "\n\t", @backtrace ) ) + ; $fatal = qq| frey-fatal|; } } warn "ERROR: $error\n"; - return - qq|
|
-		. $self->html_links( $error ) .
-		qq|
| - ; + $self->add_icon('error'); + $error = $self->html_links( $error ); + return qq|
$error $backtrace
| ; } =head1 Status line @@ -466,7 +485,6 @@ sub icon_path { my ($self,$class,$variant) = @_; -# $class ||= $self->title; sub icon_exists { my $class = shift; @@ -497,8 +515,9 @@ sub add_icon { my ($self,$variant) = @_; - my $class = ref($self); - $class = $self->class if $self->can('class'); + my $class = $self->class if $self->can('class'); + #$class ||= $self->title; + $class ||= ref($self); my $icon_path = $self->icon_path( $class, $variant ) || return; $icon_html .= qq||; @@ -669,7 +688,7 @@ my ($self) = @_; my @backtrace; - foreach ( 0 .. 5 ) { + foreach ( 1 .. 5 ) { # 0 = backtrace my ( $package,$path,$line # subroutine hasargs