1 |
package Frey::Pipe; |
package Frey::Pipe; |
2 |
use Moose; |
use Moose; |
3 |
extends 'Frey'; |
extends 'Frey::ClassLoader'; |
4 |
with 'Frey::Web'; |
with 'Frey::Web'; |
5 |
|
|
6 |
use Frey::Action; |
use Frey::Action; |
11 |
|
|
12 |
=head1 EXAMPLE |
=head1 EXAMPLE |
13 |
|
|
14 |
Frey::Feed/as_data + uri=http://blog.rot13.org/index.xml | Frey::Dumper/as_markup |
Frey::Feed/as_data + uri=http://blog.rot13.org/index.xml | Frey::View::Dumper/as_markup |
15 |
|
|
16 |
this will produce following code: |
this will produce following code: |
17 |
|
|
18 |
Frey::Dumper->new( data => |
Frey::View::Dumper->new( data => |
19 |
Frey::Feed->new( uri => 'http://blog.rot13.org/index.xml' )->as_data |
Frey::Feed->new( uri => 'http://blog.rot13.org/index.xml' )->as_data |
20 |
)->as_markup |
)->as_markup |
21 |
|
|
24 |
has pipe => ( |
has pipe => ( |
25 |
is => 'rw', |
is => 'rw', |
26 |
required => 1, |
required => 1, |
27 |
default => 'Frey::Feed/as_data+uri=http://blog.rot13.org/index.xml|Frey::Dumper/as_markup', |
default => 'Frey::Feed/as_data+uri=http://blog.rot13.org/index.xml|Frey::View::Dumper/as_markup', |
28 |
); |
); |
29 |
|
|
30 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
35 |
my $out; |
my $out; |
36 |
my $pipe; |
my $pipe; |
37 |
|
|
38 |
$self->title( ref($self) . ' | ' . $self->pipe ); |
$self->title( $self->pipe ); |
39 |
|
|
40 |
|
my @parts; |
41 |
|
|
42 |
foreach my $part ( split(/\|/, $self->pipe ) ) { |
foreach my $part ( split(/\|/, $self->pipe ) ) { |
43 |
warn "# part: '$part'"; |
warn "# part: '$part'"; |
44 |
if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) { |
if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) { |
45 |
my ( $class, $method, $args ) = ( $1, $2, $3 ); |
my ( $class, $method, $args ) = ( $1, $2, $3 ); |
46 |
push @{ $self->status }, { $class => { method => $method, args => $args } }; |
push @parts, { $class => { method => $method, args => $args } }; |
47 |
my $params = $pipe; |
my $params = $pipe; |
48 |
$params = {} unless defined $params; |
$params = {} unless defined $params; |
49 |
if ( defined $args ) { |
if ( defined $args ) { |
50 |
$args =~ s{^[\?\+\s]}{}; |
$args =~ s{^[\?\+\s]}{}; |
51 |
warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug; |
warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug; |
|
push @{ $self->status }, { $class =>$args }; |
|
52 |
map { |
map { |
53 |
my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'"; |
my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'"; |
54 |
$params->{$name} = $value; |
$params->{$name} = $value; |
59 |
warn "$class need more params than ",dump( $default ) if $html && $self->debug; # FIXME replace with query |
warn "$class need more params than ",dump( $default ) if $html && $self->debug; # FIXME replace with query |
60 |
|
|
61 |
warn "# pipe $part" if $self->debug; |
warn "# pipe $part" if $self->debug; |
62 |
my $o = $class->new( %$default ); |
my $o = $self->new_frey_class( $class, $default ); |
63 |
my $result = $o->$method; |
my $result = $o->$method; |
64 |
warn "# result ",length( $result ), " bytes ", ref($result); |
warn "# result ",length( $result ), " bytes ", ref($result); |
65 |
|
|
73 |
} |
} |
74 |
} |
} |
75 |
|
|
76 |
warn "# pipe ", $self->title; |
warn "# pipe ", $self->title, " parts ",dump( @parts ); |
77 |
|
$self->add_status( $_ ) foreach @parts; |
78 |
return $out; |
return $out; |
79 |
} |
} |
80 |
|
|