/[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 312 by dpavlin, Wed Nov 5 20:05:35 2008 UTC revision 457 by dpavlin, Wed Nov 19 16:53:13 2008 UTC
# Line 8  use Data::Dump qw/dump/; Line 8  use Data::Dump qw/dump/;
8  use File::Slurp;  use File::Slurp;
9  use List::Util;  use List::Util;
10    
11    use PPI;
12    use PPI::HTML;
13    
14  use lib 'lib';  use lib 'lib';
15    
16  extends 'Frey::ClassLoader';  extends 'Frey::ClassLoader';
# Line 100  sub joose { Line 103  sub joose {
103          return $out;          return $out;
104  }  }
105    
106  =head2 methods  sub as_markup {
   
   my @methods = $o->methods;  
   
 =cut  
   
 sub methods {  
         my $self = shift;  
   
         my ( $meta, $is_role ) = $self->class_meta;  
   
         my $attr;  
         $attr->{$_}++ foreach $meta->get_attribute_list;  
         my @methods = grep { ! defined($attr->{$_}) } $meta->get_method_list;  
         warn "# methods = ",dump( @methods ) if $self->debug;  
   
         return sort @methods;  
 }  
   
 =head1 OUTPUT GENERATION  
   
 =head2 markup  
   
   $o->markup;  
   
 =cut  
   
 sub markup {  
107          my ( $self ) = @_;          my ( $self ) = @_;
108    
109          $self->add_head( 'static/introspect.css' );          $self->add_head( 'static/introspect.css' );
# Line 152  sub markup { Line 128  sub markup {
128          }          }
129    
130          my $role_method;          my $role_method;
131            my $role_attribute;
132    
133          if ( $meta->can('roles') ) {          if ( $meta->can('roles') ) {
134                  my $role_nr = 1;                  my $role_nr = 1;
# Line 159  sub markup { Line 136  sub markup {
136                          grep { ! m/\Q$class\E/ }        # skip me                          grep { ! m/\Q$class\E/ }        # skip me
137                          map {                          map {
138                                  my $name = $_->name;                                  my $name = $_->name;
139                                  $role_method->{ $_ }->{$name} = $role_nr foreach $_->get_method_list;                                  $role_method->{    $_ }->{$name} = $role_nr foreach $_->get_method_list;
140                                    $role_attribute->{ $_ }->{$name} = $role_nr foreach $_->get_attribute_list;
141                                  qq|<a class="frey-popdown" href="/$name">$name<code>| . $name->meta->dump(2) . qq|</code></a><sup>| . $role_nr++ . qq|</sup>|;                                  qq|<a class="frey-popdown" href="/$name">$name<code>| . $name->meta->dump(2) . qq|</code></a><sup>| . $role_nr++ . qq|</sup>|;
142                          }                          }
143                          $meta->calculate_all_roles                          $meta->calculate_all_roles
# Line 170  sub markup { Line 148  sub markup {
148    
149          my @methods;          my @methods;
150          @methods = map {          @methods = map {
151                  my $method = $_;                  my $name = $_;
152                  if ( $role_method ) {                  if ( $role_method->{$name} ) {
153                          my ( $name, $nr ) = each %{ $role_method->{$_} };                          my ( $role_name, $nr ) = each %{ $role_method->{$name} };
154                          $method .= qq|<sup title="$name">$nr</sup>|;                          $name .= qq|<sup title="$role_name">$nr</sup>|;
155                  }                  }
156                  qq|<td class="m">$method</td>|                  qq|<td class="m">$name</td>|
157          } $self->methods;          } $self->class_methods( $class );
158    
159          my @attributes;          my @attributes;
160          if ( $meta->get_attribute_list ) {          if ( $meta->get_attribute_list ) {
161          @attributes = map {                  @attributes = map {
162                          my $attr = $meta->get_attribute($_);                          my $name = $_;
163                            my $attr = $meta->get_attribute($name);
164                            confess "$class attribute $name isn't blessed ",dump( $attr ) unless blessed $attr;
165                            warn "## attr $name ref ",ref( $attr ) if $self->debug;
166                          my ( $before, $title, $after ) = ( '', '', '' );                          my ( $before, $title, $after ) = ( '', '', '' );
167                          ( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->is_required;                          ( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->can('is_required') && $attr->is_required;
 warn $attr->dump(3);  
168                          foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref has_default 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_default has_trigger has_documentation has_applied_traits/ ) {
169                                  my $getter;                                  my $getter;
170                                                                    
171                                  $getter = $check;                                  $getter = $check;
172                                  $getter =~ s/^has_//;                                  $getter =~ s/^has_//;
173                                                                    
174                                  if ( $attr->$check ) {                                  if ( $attr->can($check) && $attr->$check ) {
175                                          if ( $getter eq $check ) {                                          if ( $getter eq $check ) {
176                                                  $after .= "$check";                                                  $after .= "$check";
177                                          } else {                                          } else {
# Line 203  warn $attr->dump(3); Line 183  warn $attr->dump(3);
183                                  }                                  }
184                                  $after .= ' ';                                  $after .= ' ';
185                          }                          }
186                          my $type = $attr->has_type_constraint ? $attr->type_constraint->name : '';                          my $type = $attr->can('has_type_constraint') && $attr->has_type_constraint ? $attr->type_constraint->name : '';
187                          qq|<td class="a">$before $_</td><td class="t">$type</td><td>$after</td>|  
188                  } sort $meta->get_attribute_list                          if ( $role_attribute->{$name} ) {
189                                    my ( $role_name, $nr ) = each %{ $role_attribute->{$name} };
190                                    $name .= qq|<sup title="$role_name">$nr</sup>|;
191                            }
192    
193                            qq|<td class="a">$before $name</td><td class="t">$type</td><td>$after</td>|
194                    } $meta->get_attribute_list
195          }          }
196    
197          my $table = qq|<table class="frey-introspect"><tr><th class="m">Methods</th><th class="a">Attributes</th><th>Type</th><th class="p">Properties</th></tr>|;          my $table = qq|<table class="frey-introspect"><tr><th class="m">Methods</th><th class="a">Attributes</th><th>Type</th><th class="p">Properties</th></tr>|;
# Line 217  warn $attr->dump(3); Line 203  warn $attr->dump(3);
203          }          }
204          $table .= qq|</table>|;          $table .= qq|</table>|;
205    
206          my $pod = Frey::Pod->new( class => $class )->markup;          my $pod = Frey::Pod->new( class => $class )->as_markup;
207            $pod = $pod->{body} if ref($pod);
208    
209          use Frey::Run;          my $path = $self->class_path( $class );
210          my $execute = join("\n", map { qq|<a href="/$class/$_">$_</a>| } grep { $class->can($_) } Frey::Run->execute );          my $Document = PPI::Document->new( $path );
         $execute = " execute: $execute" if $execute;  
   
         my $html = $self->page(  
                 title => "Introspect $class",  
                 body => qq|<h1>$class</h1>|  
                         . qq|<div class="frey-introspect">$superclasses\n$roles\n$execute\n|  
                         . ( $pod ? qq|<a href="#___top" title="Skip to POD" style="font-size: 80%; color: #aaa;">&darr;pod&darr</a>| : '' )  
                         . qq|$table\n$pod</div>|  
211    
212            # Create a reusable syntax highlighter
213            my $Highlight = PPI::HTML->new(
214                    line_numbers => 1,
215    #               page => 1,
216    #               colors => {
217    #                       line_number => '#CCCCCC',
218    #                       number      => '#990000',
219    #               },
220          );          );
221    
222          return $html;          # Spit out the HTML
223            my $source = $Highlight->html( $Document );
224    
225            $source =~ s{(<span.*?line_number.*>\s*)(\d+)(:\s*</span>)}{$1<a target="editor" href="/editor+$path+$2">$2</a>$3}g;
226    
227            # strip page html
228    #       $source =~ s{^.*<body[^>]+>}{}s;
229    #       $source =~ s{</body.*$}{}s;
230    
231    
232            my $runnable = join("\n",
233                    map { qq|<a href="/$class/$_">$_</a>| : '' } $self->class_runnable( $class );
234            );
235            $runnable = " runnable: $runnable" if $runnable;
236    
237            $self->title( $class );
238    
239            return join("\n",
240                    qq|<h1>$class</h1>|,
241                    qq|<div class="frey-introspect">$superclasses\n$roles\n$runnable\n|,
242                    $pod    ? qq|<a class="frey-skip" href="#___top" title="Skip to POD"    >pod</a>|    : '',
243                    $source ? qq|<a class="frey-skip" href="#source" title="Skip to source" >source</a>| : '',
244                    qq|$table\n$pod\n</div>\n|,
245                    qq|<h1>Source</h1><a name="source"></a><div class="frey-source">$source</div>|,
246            );
247  }  }
248    
249  =head1 SEE ALSO  =head1 SEE ALSO

Legend:
Removed from v.312  
changed lines
  Added in v.457

  ViewVC Help
Powered by ViewVC 1.1.26