/[Frey]/trunk/lib/Frey/Pipe.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

Contents of /trunk/lib/Frey/Pipe.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 451 - (show annotations)
Wed Nov 19 04:14:12 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2002 byte(s)
rework instance creation, more examples in config
1 package Frey::Pipe;
2 use Moose;
3 extends 'Frey';
4 with 'Frey::Web';
5
6 use Frey::Action;
7
8 =head1 DESCRIPTION
9
10 Shell pipes for structured data
11
12 =head1 EXAMPLE
13
14 Frey::Feed/data + uri=https://blog.rot13.org/index.xml | Frey::Dumper/markup
15
16 this will produce following code:
17
18 Frey::Dumper->new( data =>
19 Frey::Feed->new( uri => 'https://blog.rot13.org/index.xml' )->data
20 )->markup
21
22 =cut
23
24 has pipe => (
25 is => 'rw',
26 required => 1,
27 default => 'Frey::Feed/data+uri=https://blog.rot13.org/index.xml|Frey::Dumper/markup',
28 );
29
30 use Data::Dump qw/dump/;
31
32 sub markup {
33 my ($self) = @_;
34
35 my $out;
36 my $pipe;
37
38 $self->title( ref($self) . ' | ' . $self->pipe );
39
40 foreach my $part ( split(/\|/, $self->pipe ) ) {
41 warn "# part: '$part'";
42 if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) {
43 my ( $class, $method, $args ) = ( $1, $2, $3 );
44 push @{ $self->status }, { $class => { method => $method, args => $args } };
45 my $params = $pipe;
46 $params = {} unless defined $params;
47 if ( defined $args ) {
48 $args =~ s{^[\?\+\s]}{};
49 warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug;
50 push @{ $self->status }, { $class =>$args };
51 map {
52 my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'";
53 $params->{$name} = $value;
54 } split(/\s*\+\s/, $args)
55 }
56
57 my ( $html, $default ) = Frey::Action->new( class => $class, params => $params )->params_form;
58 warn "$class need more params than ",dump( $default ) if $html && $self->debug; # FIXME replace with query
59
60 warn "# pipe $part" if $self->debug;
61 my $o = $class->new( %$default );
62 my $result = $o->$method;
63 warn "# result ",length( $result ), " bytes ", ref($result);
64
65 $self->content_type( $o->content_type ) if $o->can('content_type');
66
67 $out = $result;
68 $pipe = { $method => $result };
69 } else {
70 die "don't know what to do with '$part' from ",$self->pipe;
71 }
72 }
73
74 warn "# pipe ", $self->title;
75
76 return $out;
77 }
78
79 1;

  ViewVC Help
Powered by ViewVC 1.1.26