/[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 53 by dpavlin, Sat Jul 5 15:19:55 2008 UTC revision 66 by dpavlin, Wed Jul 9 12:08:07 2008 UTC
# Line 11  use File::Slurp; Line 11  use File::Slurp;
11  use List::Util;  use List::Util;
12    
13  use Continuity::Widget::DomNode;  use Continuity::Widget::DomNode;
14    use lib 'lib';
15    
16  extends 'Frey';  extends 'Frey';
17    
# Line 45  sub load_package { Line 46  sub load_package {
46          my @roles_to_apply;          my @roles_to_apply;
47          $rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])});          $rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])});
48          #load the package with the hacked Moose::Meta::Role          #load the package with the hacked Moose::Meta::Role
49          eval { Class::MOP::load_class($package); };  
50          confess "Failed to load package ${package} $@" if $@;          #eval { Class::MOP::load_class($package); };
51            #confess "Failed to load package ${package} $@" if $@;
52            Class::MOP::load_class($package);
53    
54          my $meta = $package->meta;          my $meta = $package->meta;
55    
# Line 115  sub joose { Line 118  sub joose {
118          $out .= "\t\t},\n\t\tmeta: Frey.HTML,          $out .= "\t\t},\n\t\tmeta: Frey.HTML,
119                  classMethods: {                  classMethods: {
120                          renderHTML: function () {                          renderHTML: function () {
121                                  return new Joose.SimpleRequest().getText(\"inspect?module=$m;class=$c\")                                  return new Joose.SimpleRequest().getText(\"/~/" . $self->package . "\")
122                          },\n";                          },\n";
123    
124          $out .= "\t\t},\n";          $out .= "\t\t},\n";
# Line 177  sub html { Line 180  sub html {
180    
181          while (1) {          while (1) {
182    
183                  my $js = [ map {                  my $js = Continuity::Widget::DomNode->create(
184                          ( script => { type => 'text/javascript', src => $_ } )                          map {
185                  } @javascript ];                                  ( script => { type => 'text/javascript', src => $_ } )
186                  warn "# js = ",dump( $js );                          } @javascript
187                    )->to_string;
188    
189                    $js .= << '__END_OF_JS__';
190    <script type="text/javascript">
191    joose.loadComponents("../lib")
192    
193    function $(id) {
194            return document.getElementById(id)
195    }
196    
197    </script>
198    __END_OF_JS__
199    
200                  my $o;                  warn "# >>> js\n$js\n" if $self->debug;
201    
202                  my ( $class, $meta, $is_role ) = $self->load_package();                  my ( $class, $meta, $is_role ) = $self->load_package();
203    
204                    my $methods;
205                  if ( $class->can('meta') ) {                  if ( $class->can('meta') ) {
206                          $o = Continuity::Widget::DomNode->create(                          $methods = Continuity::Widget::DomNode->create(
207                                  ul => [                                  ul => [
208                                          map { (                                          map { (
209                                                  li => [ a => { href => $_ } => [ $_ ] ]                                                  li => [ a => { href => '/~/' . $self->package . '/' . $_ } => [ $_ ] ]
210                                          ) } $self->methods                                          ) } $self->methods
211                                  ]                                  ]
212                          )->to_string;                          )->to_string;
213                  } else {                  } else {
214                          $o = '<b>not introspectable</b>';                          $methods = '<b>not introspectable</b>';
215                  }                  }
216    
217                  warn "# o = ",dump( $o );                  my $attributes = Continuity::Widget::DomNode->create(
218                                            ul => [
219                                    map {
220                                            my $attr = $class->get_attribute($_);
221                                            warn "## $_ ", $attr->is_required ? 'required' : 'optional';
222                                            ( li => [ a => { href => '/~/' . $self->package . '/' . $_ } => [ $_ ], ( $attr->is_required ? ' <b>required</b>' : '' ) ] )
223                                    } $class->get_attribute_list
224                            ],
225                    )->to_string;
226    
227                  my $doc = Continuity::Widget::DomNode->create(                  my $doc = Continuity::Widget::DomNode->create(
228                          html => [                          html => [
229                                  head => [                                  head => [
230                                          link => { rel=>"stylesheet", href=>"/static/app.css", type=>"text/css", media=>"screen" },                                          link => { rel=>"stylesheet", href=>"/static/app.css", type=>"text/css", media=>"screen" },
231  #                                       $js,                                          $js,
232                                            title => [ 'Introspect ', $self->package ],
233                                  ],                                  ],
234                                  body => [                                  body => [
235                                          h1 => [ 'Introspect ', $self->package ],                                          h1 => [ $self->package ],
236                                          $o,                                          h2 => [ 'Methods' ],
237                                            $methods,
238                                            h2 => [ 'Atrributes' ],
239                                            $attributes,
240                                  ],                                  ],
241                          ]                          ]
242                  );                  );
243    
244                  $request->print($doc->to_string);                  $request->print($doc->to_string);
245                  warn "# html = ", $doc->to_string;                  warn "# >>> html\n", $doc->to_string, "\n";
246                  $request->next;                  $request->next;
247          }          }
248          warn "# exit html";          warn "# exit html";

Legend:
Removed from v.53  
changed lines
  Added in v.66

  ViewVC Help
Powered by ViewVC 1.1.26