/[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 507 - (show annotations)
Tue Nov 25 00:26:15 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2093 byte(s)
new add_status to add data to status line (not working fully yet)
1 package Frey::Pipe;
2 use Moose;
3 extends 'Frey::ClassLoader';
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/as_data + uri=http://blog.rot13.org/index.xml | Frey::View::Dumper/as_markup
15
16 this will produce following code:
17
18 Frey::View::Dumper->new( data =>
19 Frey::Feed->new( uri => 'http://blog.rot13.org/index.xml' )->as_data
20 )->as_markup
21
22 =cut
23
24 has pipe => (
25 is => 'rw',
26 required => 1,
27 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/;
31
32 sub as_markup {
33 my ($self) = @_;
34
35 my $out;
36 my $pipe;
37
38 $self->title( $self->pipe );
39
40 my @parts;
41
42 foreach my $part ( split(/\|/, $self->pipe ) ) {
43 warn "# part: '$part'";
44 if ( $part =~ m{^([^/]+)/([^\+\?]+)(.*)?$} ) {
45 my ( $class, $method, $args ) = ( $1, $2, $3 );
46 push @parts, { $class => { method => $method, args => $args } };
47 my $params = $pipe;
48 $params = {} unless defined $params;
49 if ( defined $args ) {
50 $args =~ s{^[\?\+\s]}{};
51 warn "# class $class method $method args '$args'", $pipe ? " pipe args " . join(',',keys %$pipe) : '' if $self->debug;
52 map {
53 my ( $name, $value ) = ( $1, $2 ) if m{^([^=]+)=(.+)$} || confess "can't parse '$_'";
54 $params->{$name} = $value;
55 } split(/\s*\+\s/, $args)
56 }
57
58 my ( $html, $default ) = Frey::Action->new( class => $class, params => $params )->params_form;
59 warn "$class need more params than ",dump( $default ) if $html && $self->debug; # FIXME replace with query
60
61 warn "# pipe $part" if $self->debug;
62 my $o = $self->new_frey_class( $class, $default );
63 my $result = $o->$method;
64 warn "# result ",length( $result ), " bytes ", ref($result);
65
66 $self->content_type( $o->content_type ) if $o->can('content_type');
67
68 $out = $result;
69 $method =~ s{^as_}{};
70 $pipe = { $method => $result };
71 } else {
72 die "don't know what to do with '$part' from ",$self->pipe;
73 }
74 }
75
76 warn "# pipe ", $self->title, " parts ",dump( @parts );
77 $self->add_status( $_ ) foreach @parts;
78 return $out;
79 }
80
81 1;

  ViewVC Help
Powered by ViewVC 1.1.26