Bot-Pastebot

 view release on metacpan or  search on metacpan

lib/Bot/Pastebot/Server/Http.pm  view on Meta::CPAN

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
}
 
### Fetch paste.
 
if ($url =~ m{^/(\d+)(?:\?(.*?)\s*)?$}) {
  my ($num, $params) = ($1, $2);
  my ($nick, $summary, $paste) = fetch_paste($num);
 
  if (defined $paste) {
    my @flag_names = qw(ln tidy hl wr);
    my $cookie = parse_cookie($request->headers->header('Cookie'));
    my $query  = parse_content($params);
 
    ### Make the paste pretty.
 
    my $store = is_true($query->{store});
    my %flags;
    for my $flag (@flag_names) {
      $flags{$flag} = $store || exists $query->{$flag}
                    ? is_true( $query->{$flag})
                    : is_true($cookie->{$flag});

lib/Bot/Pastebot/Server/Http.pm  view on Meta::CPAN

415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
        nick     => $nick,
        summary  => $summary,
        paste    => $paste,
        footer   => PAGE_FOOTER,
        tx       => ( $tx ? "checked" : "" ),
        map { $_ => $flags{$_} ? "checked" : "" } @flag_names,
      }
    );
    if ($store) {
      for my $flag (@flag_names) {
        $response->push_header('Set-Cookie' => cookie($flag => $flags{$flag}, $request));
      }
    }
  }
 
  $heap->{wheel}->put( $response );
  return;
}
 
my $response = HTTP::Response->new(404);
$response->push_header( 'Content-type', 'text/html; charset=utf-8' );

lib/Bot/Pastebot/WebUtil.pm  view on Meta::CPAN

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# static pages, and do template things with them.
#
# TODO - We could probably replace them with an actual CPAN library or
# two.
 
$Bot::Pastebot::WebUtil::VERSION = '0.600';
use strict;
 
 
our @EXPORT_OK = qw(
  url_decode url_encode parse_content parse_cookie static_response
  dump_content dump_query_as_response base64_decode html_encode
  is_true cookie redirect
);
 
#------------------------------------------------------------------------------
# Build two URL-encoding maps.  Map non-printable characters to

lib/Bot/Pastebot/WebUtil.pm  view on Meta::CPAN

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  my $hex = lc(unpack('H2', $character));
 
  # Map characters to their hex values, including the escape.
  $raw_to_url{ $character } = '%' . $hex;
 
  # Map hex codes (lower- and uppercase) to characters.
  $url_to_raw{    $hex } = $character;
  $url_to_raw{ uc $hex } = $character;
}
 
# Return a cookie string for a Set-Cookie header. The request argument is
# used to figure out domain.
sub cookie {
  my ($name, $value, $request) = @_;
 
  return CGI::Cookie->new(
    -name => $name,
    -value => $value,
    -expires => '+36M',
    -domain => (split /:/, $request->headers->header('Host'))[0],
    -path => '/',
  )->as_string;
}
 
# Decode url-encoded data.  This code was shamelessly stolen from
# Lincoln Stein's CGI.pm module.  Translate plusses to spaces, and

lib/Bot/Pastebot/WebUtil.pm  view on Meta::CPAN

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
      }
    }
    else {
      $content{$param} = $value;
    }
  }
 
  return \%content;
}
 
# Parse a cookie string (found usually in the Cookie: header), returning a
# hashref containing cookies values, not CGI::Cookie objects.
sub parse_cookie {
  my ($cookie) = @_;
 
  return {} if not defined $cookie;
  return { map url_decode($_), map /([^=]+)=?(.*)/s, split /; ?/, $cookie };
}
 
sub _render_template {
  my ($template, $filename, $record) = @_;



( run in 0.970 second using v1.01-cache-2.11-cpan-5f2e87ce722 )