Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.46 KB | None | 0 0
  1. post '/new' => sub {
  2.   my $title = request.params<title> // '';
  3.   my $text = request.params<text> // '';
  4.  
  5.   my $id = 1;
  6.   try {
  7.     $id = get_id();
  8.   }
  9.   my $pubdate = now;
  10.  
  11.   my %a = 'id' => $id,
  12.           'title' => $title,
  13.           'pubdate' => $pubdate,
  14.           'text' = $text;
  15.   my $json = to-json(%a);
  16.   my $filename = 'data/' ~ $id ~ '.json';
  17.   my $fh = open $filename, :w;
  18.   $fh.say($json);
  19.   $fh.close();
  20.  
  21.   say 'Article enregistré !';
  22. };
  23.  
  24. $ perl6 app.p6
  25. Entering the development dance floor: http://0.0.0.0:3000
  26. [2016-02-16T14:51:35Z] Started HTTP server.
  27. [2016-02-16T14:51:42Z] GET /new HTTP/1.1
  28. [2016-02-16T14:52:18Z] POST /new HTTP/1.1
  29. Cannot modify an immutable Str
  30.   in sub  at app.p6 line 44
  31.   in sub dispatch at /home/emeric/.rakudobrew/moar-2015.12/install/share/perl6/site/sources/5697700BC6E98F8C57CCB13BC967A5F8C7E84E9E line 137
  32.   in sub dispatch-psgi at /home/emeric/.rakudobrew/moar-2015.12/install/share/perl6/site/sources/5697700BC6E98F8C57CCB13BC967A5F8C7E84E9E line 157
  33.   in method handler at /home/emeric/.rakudobrew/moar-2015.12/install/share/perl6/site/sources/C31909E8F4ABB3D9DBB1235E43CF6EA2A59BE75A line 34
  34.   in method run at /home/emeric/.rakudobrew/moar-2015.12/install/share/perl6/site/sources/7FC10A725DD1B287E23A8BF3056BA3C22A2F2BBD line 184
  35.   in sub baile at /home/emeric/.rakudobrew/moar-2015.12/install/share/perl6/site/sources/5697700BC6E98F8C57CCB13BC967A5F8C7E84E9E line 165
  36.   in block <unit> at app.p6 line 57
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement