/[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 455 - (show annotations)
Wed Nov 19 15:28:23 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2048 byte(s)
rename invocable events with prefix as_ with fallback in Frey::Web

This started with brute-force rename using:

  perl -p -i -n -e 's/sub markup/sub as_markup/'  `grep -lr 'sub markup' lib t`
  perl -p -i -n -e 's/sub data/sub as_data/'      `grep -lr 'sub data' lib t`
  perl -p -i -n -e 's/sub sponge/sub as_sponge/'  `grep -lr 'sub sponge' lib t`

  perl -p -i -n -e 's/->markup/->as_markup/'      `grep -lr -- '->markup' lib t`
  perl -p -i -n -e 's/->data/->as_data/'          `grep -lr -- '->data' lib t`
  perl -p -i -n -e 's/->sponge/->as_sponge/'      `grep -lr -- '->sponge' lib t`

  perl -p -i -n -e 's!/markup!/as_markup!'        `grep -lr -- '/markup' lib t etc`
  perl -p -i -n -e 's!/data!/as_data!'            `grep -lr -- '/data' lib t etc`
  perl -p -i -n -e 's!/sponge!/as_sponge!'        `grep -lr -- '/sponge' lib t etc`

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/as_data + uri=https://blog.rot13.org/index.xml | Frey::Dumper/as_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' )->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=https://blog.rot13.org/index.xml|Frey::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( 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 $method =~ s{^as_}{};
69 $pipe = { $method => $result };
70 } else {
71 die "don't know what to do with '$part' from ",$self->pipe;
72 }
73 }
74
75 warn "# pipe ", $self->title;
76
77 return $out;
78 }
79
80 1;

  ViewVC Help
Powered by ViewVC 1.1.26