--- trunk/lib/Frey/Pipe.pm 2008/11/05 08:21:10 300 +++ trunk/lib/Frey/Pipe.pm 2008/11/19 19:28:09 467 @@ -1,5 +1,9 @@ package Frey::Pipe; use Moose; +extends 'Frey::ClassLoader'; +with 'Frey::Web'; + +use Frey::Action; =head1 DESCRIPTION @@ -7,56 +11,69 @@ =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', ); use Data::Dump qw/dump/; -sub markup { +sub as_markup { my ($self) = @_; my $out; my $pipe; + $self->title( ref($self) . ' | ' . $self->pipe ); + foreach my $part ( split(/\|/, $self->pipe ) ) { warn "# part: '$part'"; - if ( $part =~ m{^([^/]+)/([^\+]+)(\+.*)?$} ) { + 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/^\+//; - warn "# class $class method $method args $args", $pipe ? " pipe args " . join(',',keys %$pipe) : ''; + $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{^([^=]+)=(.+)$}; + my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'"; $params->{$name} = $value; - } split(/[\s\+]/, $args) + } split(/\s*\+\s/, $args) } - my $code = '$result = ' . $class . '->new' . dump( %$params ) . '->' . $method . '();'; - warn "# pipe $part -> $code"; - my $result; - eval $code; - die $@ if $@; - warn "# result ",ref( $result ); - $out .= qq{$part} . dump( $result ) . '
'; + + 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 + + warn "# pipe $part" if $self->debug; + my $o = $self->new_frey_class( $class, $default ); + my $result = $o->$method; + warn "# result ",length( $result ), " bytes ", ref($result); + + $self->content_type( $o->content_type ) if $o->can('content_type'); + + $out = $result; + $method =~ s{^as_}{}; $pipe = { $method => $result }; } else { die "don't know what to do with '$part' from ",$self->pipe; } } + warn "# pipe ", $self->title; + return $out; }