/[Frey]/branches/mojo/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 /branches/mojo/lib/Frey/Introspect.pm

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

revision 234 by dpavlin, Sat Nov 1 13:06:31 2008 UTC revision 235 by dpavlin, Sat Nov 1 15:36:33 2008 UTC
# Line 129  sub load_package { Line 129  sub load_package {
129    
130  =head1 OUTPUT GENERATION  =head1 OUTPUT GENERATION
131    
132  =head2 request  =head2 markup
133    
134    $o->request( $request );    $o->markup;
135    
136  =cut  =cut
137    
138  sub request {  sub markup {
139          my ( $self, $request ) = @_;          my ( $self ) = @_;
140    
141          $self->add_head( 'static/introspect.css' );          $self->add_head( 'static/introspect.css' );
142    
143          while (1) {          my ( $meta, $is_role ) = $self->load_package;
144    
145                  my ( $meta, $is_role ) = $self->load_package;          my $package = $self->package;
146    
147                  my $package = $self->package;          my @methods;
148            @methods = map { qq|<td class="m">$_</td>| } $self->methods;
149    
150                  my @methods;          my @attributes;
151                  @methods = map { qq|<td class="m">$_</td>| } $self->methods;          if ( $meta->get_attribute_list ) {
152            @attributes = map {
153                  my @attributes;                          my $attr = $meta->get_attribute($_);
154                  if ( $meta->get_attribute_list ) {                          my ( $before, $title, $after ) = ( '', '', '' );
155                  @attributes = map {                          ( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->is_required;
                                 my $attr = $meta->get_attribute($_);  
                                 my ( $before, $title, $after ) = ( '', '', '' );  
                                 ( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->is_required;  
156  warn $attr->dump(3);  warn $attr->dump(3);
157                                  foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref has_trigger has_documentation has_applied_traits/ ) {                          foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref has_trigger has_documentation has_applied_traits/ ) {
158                                          my $getter;                                  my $getter;
159                                                                            
160                                          $getter = $check;                                  $getter = $check;
161                                          $getter =~ s/^has_//;                                  $getter =~ s/^has_//;
162                                                                            
163                                          if ( $attr->$check ) {                                  if ( $attr->$check ) {
164                                                  if ( $getter eq $check ) {                                          if ( $getter eq $check ) {
165                                                          $after .= "$check";                                                  $after .= "$check";
166                                                  } else {                                          } else {
167                                                          $after .= qq{<span class="frey-popdown">$check};                                                  $after .= qq{<span class="frey-popdown">$check};
168                                                          $after .= '<code>' . $attr->$getter->dump . '</code>' if $getter ne $check;                                                  $after .= '<code>' . $attr->$getter->dump . '</code>' if $getter ne $check;
169                                                          $after .= '</span>';                                                  $after .= '</span>';
                                                 }  
170                                          }                                          }
                                         $after .= ' ';  
171                                  }                                  }
172                                  qq|<td class="a">$before $_</td><td>$after</td>|                                  $after .= ' ';
173                          } sort $meta->get_attribute_list                          }
174                  }                          qq|<td class="a">$before $_</td><td>$after</td>|
175                    } sort $meta->get_attribute_list
176            }
177    
178                  my $table = qq|<table class="frey-object-browser"><tr><th class="m">Methods</th><th class="a">Attributes</th><th class="p">Properties</th></tr>|;          my $table = qq|<table class="frey-object-browser"><tr><th class="m">Methods</th><th class="a">Attributes</th><th class="p">Properties</th></tr>|;
179                  while ( @methods || @attributes ) {          while ( @methods || @attributes ) {
180                          my ($m,$a) = ( shift @methods, shift @attributes );                  my ($m,$a) = ( shift @methods, shift @attributes );
181                          $m ||= '<td></td>';                  $m ||= '<td></td>';
182                          $a ||= '<td></td>';                  $a ||= '<td></td>';
183                          $table .= qq|<tr>$m$a</tr>|;                  $table .= qq|<tr>$m$a</tr>|;
184                  }          }
185                  $table .= qq|</table>|;          $table .= qq|</table>|;
186    
187                  my ( $superclasses, $roles ) = ( '<b>Role</b>', '' );          my ( $superclasses, $roles ) = ( '<b>Role</b>', '' );
188                  if ( ! $is_role ) {          if ( ! $is_role ) {
189                          if ( $meta->superclasses ) {                  if ( $meta->superclasses ) {
190                                  $superclasses = 'Superclasses: ' .                          $superclasses = 'Superclasses: ' .
191                                          join(', ',                                  join(', ',
192                                                  map {                                          map {
193                                                          my $name = $_->meta->name;                                                  my $name = $_->meta->name;
194                                                          qq|<a class="frey-popdown" href="/~/$name">$name<code>| . $_->meta->dump(2) . qq|</code></a>|;                                                  qq|<a class="frey-popdown" href="/~/$name">$name<code>| . $_->meta->dump(2) . qq|</code></a>|;
195                                                  }                                          }
196                                                  #grep { $_ ne 'Moose::Object' }                                          #grep { $_ ne 'Moose::Object' }
197                                                  $meta->superclasses                                          $meta->superclasses
198                                          );                                  );
                         }  
199                  }                  }
200            }
201    
202                  if ( $meta->can('roles') ) {          if ( $meta->can('roles') ) {
203                          $roles = join(', ',                  $roles = join(', ',
204                                  grep { ! m/\Q$package\E/ }      # skip me                          grep { ! m/\Q$package\E/ }      # skip me
205                                  map {                          map {
206                                          my $name = $_->name;                                  my $name = $_->name;
207                                          qq|<a class="frey-popdown" href="/~/$name">$name<code>| . $name->meta->dump(2) . qq|</code></a>|;                                  qq|<a class="frey-popdown" href="/~/$name">$name<code>| . $name->meta->dump(2) . qq|</code></a>|;
208                                  }                          }
209                                  $meta->calculate_all_roles                          $meta->calculate_all_roles
210                          );                  );
211                          $roles = " with roles: $roles" if $roles;                  $roles = " with roles: $roles" if $roles;
212                  }          }
213    
214                  my $pod = Frey::Pod->new( class => $package )->markup;          my $pod = Frey::Pod->new( class => $package )->markup;
215    
216                  use Frey::Run;          use Frey::Run;
217                  my $execute = join("\n", map { qq|<a href="/$_/$package">$_</a>| } grep { $package->can($_) } Frey::Run->execute );          my $execute = join("\n", map { qq|<a href="/$_/$package">$_</a>| } grep { $package->can($_) } Frey::Run->execute );
218                  $execute = " execute: $execute" if $execute;          $execute = " execute: $execute" if $execute;
219    
220                  my $html = $self->page(          my $html = $self->page(
221                          title => "Introspect $package",                  title => "Introspect $package",
222                          body => qq|<h1>$package</h1>|                  body => qq|<h1>$package</h1>|
223                                  . qq|$superclasses\n$roles\n$execute\n|                          . qq|$superclasses\n$roles\n$execute\n|
224                                  . ( $pod ? qq|<a href="#___top" title="Skip to POD" style="font-size: 80%; color: #aaa;">&darr;pod&darr</a>| : '' )                          . ( $pod ? qq|<a href="#___top" title="Skip to POD" style="font-size: 80%; color: #aaa;">&darr;pod&darr</a>| : '' )
225                                  . qq|$table\n$pod|                          . qq|$table\n$pod|
226    
227                  );          );
228    
229                  $request->print($html);          return $html;
                 warn "# >>> html ",length($html)," bytes\n";  
                 $request->next;  
         }  
         warn "# exit html";  
230  }  }
231    
232  =head1 SEE ALSO  =head1 SEE ALSO

Legend:
Removed from v.234  
changed lines
  Added in v.235

  ViewVC Help
Powered by ViewVC 1.1.26