--- trunk/lib/Frey/Pipe.pm 2008/11/17 17:55:50 377 +++ trunk/lib/Frey/Pipe.pm 2008/11/25 00:26:15 507 @@ -1,7 +1,9 @@ package Frey::Pipe; use Moose; +extends 'Frey::ClassLoader'; +with 'Frey::Web'; -with 'Frey::Config'; +use Frey::Action; =head1 DESCRIPTION @@ -9,62 +11,71 @@ =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( $self->pipe ); + + my @parts; + foreach my $part ( split(/\|/, $self->pipe ) ) { warn "# part: '$part'"; if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) { my ( $class, $method, $args ) = ( $1, $2, $3 ); + push @parts, { $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) : ''; + warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug; map { my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'"; $params->{$name} = $value; } split(/\s*\+\s/, $args) } - my $default = $self->config( $class ); - foreach my $arg ( keys %$default ) { - $params->{$arg} = $default->{$arg} if ! $params->{$arg}; - } - 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; } } - return '' . $self->pipe . '' . $out; + warn "# pipe ", $self->title, " parts ",dump( @parts ); + $self->add_status( $_ ) foreach @parts; + return $out; } 1;