--- trunk/lib/Frey/Pipe.pm 2008/11/18 17:11:08 420 +++ trunk/lib/Frey/Pipe.pm 2009/01/06 23:44:59 953 @@ -1,8 +1,9 @@ package Frey::Pipe; use Moose; -extends 'Frey'; +extends 'Frey::Class::Loader'; with 'Frey::Web'; +use lib 'lib'; use Frey::Action; =head1 DESCRIPTION @@ -11,67 +12,96 @@ =head1 EXAMPLE - Frey::Feed/data + uri=http://blog.rot13.org/index.xml | Frey::Dumper/markup + Frey::Feed/as_data + uri=http://blog.rot13.org/index.xml | Frey::View::Dumper/as_markup this will produce following code: - Frey::Dumper->new( data => - Frey::Feed->new( uri => 'http://blog.rot13.org/index.xml' )->data - )->markup + Frey::View::Dumper->new( data => + Frey::Feed->new( uri => 'http://blog.rot13.org/index.xml' )->as_data + )->as_markup =cut has pipe => ( is => 'rw', required => 1, - default => 'Frey::Feed/data+uri=http://blog.rot13.org/index.xml|Frey::Dumper/markup', + default => 'Frey::Feed/as_data+uri=http://blog.rot13.org/index.xml|Frey::View::Dumper/as_markup', ); +sub render_pipe { 'radio' }; + use Data::Dump qw/dump/; -sub markup { +sub as_markup { my ($self) = @_; my $out; my $pipe; - $self->title( ref($self) . ' | ' . $self->pipe ); + $self->title( $self->pipe ); + + my @parts; foreach my $part ( split(/\|/, $self->pipe ) ) { warn "# part: '$part'"; if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) { my ( $class, $method, $args ) = ( $1, $2, $3 ); - push @{ $self->status }, { $class => { method => $method, args => $args } }; my $params = $pipe; $params = {} unless defined $params; if ( defined $args ) { $args =~ s{^[\?\+\s]}{}; warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug; - push @{ $self->status }, { $class =>$args }; map { my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'"; $params->{$name} = $value; - } split(/\s*\+\s/, $args) + } split(/[;&]/, $args) } my ( $html, $default ) = Frey::Action->new( class => $class, params => $params )->params_form; warn "$class need more params than ",dump( $default ) if $html && $self->debug; # FIXME replace with query - my $code = '$result = ' . $class . '->new' . dump( %$default ) . '->' . $method . '();'; - warn "# pipe $part -> $code" if $self->debug; - my $result; - eval $code; - die $@ if $@; - warn "# result ",ref( $result ); -# $out .= qq{$part} . dump( $result ) . '
'; + warn "# pipe $part" if $self->debug; + my $o = $self->new_frey_class( $class, $default ); + + # XXX copy depends from parts of pipe + if ( $o->can('depends') ) { + $o->depends; + my $current_head; + $current_head->{$_}++ foreach $self->head; + foreach ( $o->head ) { + next if $current_head->{$_}++; + $self->add_head( $_ ); + } + } + + my $result = $o->$method; + warn "# result ",length( $result ), " bytes ", ref($result); + + my $current_status; + $current_status->{$_}++ foreach $self->status; + foreach ( $o->status ) { + next if $current_status->{$_}++; + $self->add_status( $_ ); + warn "# pipe add_status: $_"; + } + + $self->content_type( $o->content_type ) if $o->can('content_type'); + $out = $result; + $method =~ s{^as_}{}; $pipe = { $method => $result }; + push @parts, { $class . '->' . $method => $result }; } else { die "don't know what to do with '$part' from ",$self->pipe; } } - warn "# pipe ", $self->title, dump( $self->status ); + $pipe = $self->pipe; + + $out = $self->error( + qq|$pipe = $out not scalar\n| + . $self->html_dump($out) + ) if ref $out; return $out; }