/[Frey]/trunk/lib/Frey/Introspect.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Introspect.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 100 by dpavlin, Fri Jul 11 19:19:42 2008 UTC revision 133 by dpavlin, Tue Jul 15 13:58:07 2008 UTC
# Line 114  sub methods { Line 114  sub methods {
114          my @methods = grep { ! defined($attr->{$_}) } $class->get_method_list;          my @methods = grep { ! defined($attr->{$_}) } $class->get_method_list;
115          warn "# methods = ",dump( @methods ) if $self->debug;          warn "# methods = ",dump( @methods ) if $self->debug;
116    
117          return @methods;          return sort @methods;
118  }  }
119    
120  use Frey::ClassLoader;  use Frey::ClassLoader;
# Line 138  sub html { Line 138  sub html {
138    
139          while (1) {          while (1) {
140    
141                  my $js = $self->head_javascript;                  my ( $class, $meta, $is_role ) = $self->load_package;
                 $js .= << '__END_OF_JS__';  
 <script type="text/javascript">  
 joose.loadComponents("../lib")  
   
 function $(id) {  
         return document.getElementById(id)  
 }  
142    
143  </script>                  my $package = $self->package;
 __END_OF_JS__  
144    
145                  my ( $class, $meta, $is_role ) = $self->load_package;                  my @methods;
146                    @methods = map { qq|<td><a href="/~/$package/$_">$_</a></td>| } $self->methods if $class->can('meta');
147    
148                  my $methods;                  my @attributes;
149                  if ( $class->can('meta') ) {                  if ( $class->get_attribute_list ) {
150                          $methods = dom2html(                  @attributes = map {
151                                  h2 => [ 'Methods' ],                                  my $attr = $class->get_attribute($_);
152                                  ul => [                                  my ( $before, $title, $after ) = ( '', '', '' );
153                                          map { (                                  ( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->is_required;
154                                                  li => [ a => { href => '/~/' . $self->package . '/' . $_ } => [ $_ ] ]                                  qq|<td>$before<a href="/~/$package/$_?"$title>$_</a>$after</td>|
155                                          ) } $self->methods                          } sort $class->get_attribute_list
                                 ]  
                         );  
                 } else {  
                         $methods = '<b>not introspectable</b>';  
156                  }                  }
157    
158                  my $attributes;                  my $table = qq|<table><tr><th>Methods</th><th>Attributes</th></tr>|;
159                  if ( $class->get_attribute_list ) {                  while ( @methods || @attributes ) {
160                          $attributes = dom2html(                          my ($m,$a) = ( shift @methods, shift @attributes );
161                                  h2 => [ 'Atrributes' ],                          $m ||= '<td></td>';
162                                  table => [                          $a ||= '<td></td>';
163                                          map {                          $table .= qq|<tr>$m$a</tr>|;
                                                 my $attr = $class->get_attribute($_);  
                                                 warn "## $_ ", $attr->is_required ? 'required' : 'optional';  
                                                 ( tr => [  
                                                         td => [ a => { href => '/~/' . $self->package . '/' . $_ } => [ $_ ] ],  
                                                         td => [ $attr->is_required ? ' <b>required</b>' : '' ],  
                                                 ] )  
                                         } $class->get_attribute_list  
                                 ],  
                         );  
                 } else {  
                         $attributes = '<b>no attributes</b>';  
164                  }                  }
165                    $table .= qq|</table>|;
166    
167                    my $classes =
168                            qq|<div class="classes">| .
169                            Frey::ClassBrowser->new->markup .
170                            qq|</div>|;
171    
172                    $self->add_css( 'static/introspect.css' );
173    
174                    warn "## css = ",dump( $self->css );
175    
176                    my $superclasses = 'Role';
177                    $superclasses = 'Superclasses: ' . join(', ',
178                            map {
179                                    my $s = $_->meta->name;
180                                    qq|<a href="/~/$s">$s</a>|
181                            }
182                            #grep { $_ ne 'Moose::Object' }
183                            $meta->superclasses
184                    ) if ! $is_role && $meta->superclasses;
185    
186                    my $pod = Frey::Pod->new( class => $package )->markup;
187    
188                    my $html = $self->page(
189                            title => "Introspect $package",
190                            body => qq|<h1>$package</h1>|
191                                    . ( $pod ? qq|<a href="#___top" title="Skip to POD" style="font-size: 80%; color: #aaa;">&darr;pod&darr</a>  | : '' )
192                                    . qq|$superclasses\n$table\n$pod\n$classes|,
193    
                 my $html = dom2html(  
                         html => [  
                                 head => [  
                                         link => { rel=>"stylesheet", href=>"/static/app.css", type=>"text/css", media=>"screen" },  
                                         $js,  
                                         title => [ 'Introspect ', $self->package ],  
                                 ],  
                                 body => [  
                                         h1 => [ $self->package ],  
                                         $methods,  
                                         $attributes,  
                                 ],  
                         ]  
194                  );                  );
195    
196                  $request->print($html);                  $request->print($html);

Legend:
Removed from v.100  
changed lines
  Added in v.133

  ViewVC Help
Powered by ViewVC 1.1.26