Re: Looking for introductory to advanced examples of RESTful programming in Perl

2015-08-11 Thread Kenneth Wolcott
Hello again;

> take a look at
>
> http://www.todobackend.com/
>
> you can port the mojolicious one to Dancer as a learning experience.

Thank you for the tips...

> You'd have to try any of the web framework for creating RESTful API
> You can try Mojolicious
> http://mojolicio.us/perldoc

> Or you can try dancer2.
> https://metacpan.org/pod/Dancer2::Cookbook#Writing-a-REST-application
> https://metacpan.org/pod/Dancer2::Tutorial

Again, thanks for the tips...

Perhaps I didn't phrase my question very well.

If I have an API for JIRA or an API for some other application that is
provided in a RESTful manner, do I use Dancer or Mojolicious?

What would I do if the API I needed to interface with in Perl was JSON?

A long time ago I wrote a portion of a Perl-based web app that
interfaced with an XML-based API, but I've never done JSON or RESTful
with Perl.

Thanks,
Ken

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Looking for introductory to advanced examples of RESTful programming in Perl

2015-08-11 Thread Hao Wu
take a look at

http://www.todobackend.com/

you can port the mojolicious one to Dancer as a learning experience.



On Tue, Aug 11, 2015 at 6:50 PM, Kenneth Wolcott 
wrote:

> Hello;
>
>   I'm looking for introductory to advanced examples of RESTful
> programming in Perl preferably with some good explanations and best
> practices.
>
> Thanks,
> Ken Wolcott
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Looking for introductory to advanced examples of RESTful programming in Perl

2015-08-11 Thread Raj Barath
You'd have to try any of the web framework for creating RESTful API
You can try Mojolicious 
http://mojolicio.us/perldoc

Or you can try dancer2.
https://metacpan.org/pod/Dancer2::Cookbook#Writing-a-REST-application
https://metacpan.org/pod/Dancer2::Tutorial

-Raj


On Tue, Aug 11, 2015 at 10:50 PM, Kenneth Wolcott 
wrote:

> Hello;
>
>   I'm looking for introductory to advanced examples of RESTful
> programming in Perl preferably with some good explanations and best
> practices.
>
> Thanks,
> Ken Wolcott
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Looking for introductory to advanced examples of RESTful programming in Perl

2015-08-11 Thread Kenneth Wolcott
Hello;

  I'm looking for introductory to advanced examples of RESTful
programming in Perl preferably with some good explanations and best
practices.

Thanks,
Ken Wolcott

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reading from socket

2015-08-11 Thread Jim Gibson

> On Aug 11, 2015, at 3:16 PM, Chris Knipe  wrote:
> 
> Lastly, you're reading from a socket so there's no guarantee that
> the buffer string is going to necessarily end at the termination
> boundary. Perhaps the protocol guarantees that, but the socket
> surely doesn't. You may need to look for that terminating
> sequence in the middle of the buffer.
> 
> 
> But isn't that exactly why we set things like autoflush(1) or $|=1?  After 
> the data stream has been sent from the server (i.e. CRLF.CRLF) the server 
> stops transmitting data and waits for the next command, so there's no chance 
> that a second data stream may be received by the client socket, at least not 
> until the client socket issues a new command.  

The TCP transmission protocol is not line-oriented, so, depending upon how the 
remote node has their socket configured, each buffer of data from the server 
could possibly contain multiple lines and may not end with a complete line. The 
packet containing the end of the partial line could be delayed or never arrive 
if the connection is broken.

Transmit and receive are asynchronous, so can be going on simultaneously. Your 
application protocol may require the server to wait for a command from the 
client before resuming transmission of the next packet, but that is not 
required by the TCP protocol.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reading from socket

2015-08-11 Thread Chris Knipe
On Wed, Aug 12, 2015 at 12:16 AM, Chris Knipe  wrote:



> Lines *should* be terminated by CRLF (provided the 8-bit encoding doesn't
> mess up the detection), and the entire data stream is then terminated with
> a CRLF.CRLF (similar to a SMTP message for example in terms of protocol).
>

Looking at Data::Dumper - it actually looks like latin1 to me *seriously
confused*

$VAR1 =
"L\\xAF\\xF3\\xDDWJL\\x94\\xEB\\xB2\\xF8\\xE1\\xACZ\\x89Ul;\\xB7\\xDE}1
'\\xCA\\xC2\\xE3uZ\\xFF7\\xD2=}\\xA8q:;\@,%:_\x{286}-\\xD8\\xF8\\xF9E\x{2c1}5\\xD6j+Z?\\xA6\\x9F\\xEC7\\xEC\\xBB4'CNld\\xBE\\xE6=J\\xFDL\x{7d4}\\xF9nOz(w\\x83\\xEA\\xD6UHi\\xD5p+\\xBFa\\xADvG\\xD4*a\\xEA\\xBBC\\xD0\x{9631}=J\\x96
\\xFD&\\xF9MxD\\x89g\\x9EA\\xBD5\\xB4R\\xA0\\xE5sp\\xF3\\xD2x\\x84\xEC\\x92y\\x91\\\x{7c1}\\xB1\\xA1\\x9C\\xB73BE\\xA9)\\xCAf\\xC8\\xEE+\\xA1b\\x8E\\xFCM!\@\\xBE^\\xB5d";

And yes - there's numerous characters in the the above that actually didn't
even make it to the email...
http://www.savage.za.org/webpics/perl-encode.png


-- 

Regards,
Chris Knipe


Re: reading from socket

2015-08-11 Thread Chris Knipe
>
> Firstly, if the handle isn't being read with binmode set then
> perhaps the \r\n are being converted to \n (if this is Windows)?
> How are you creating/initializing the socket?
>


Unfortunately, with or without binmode, there's no difference to the
matching (from what I can tell)

Socket creation:
my $TCPSocket = new IO::Socket::INET (PeerHost => "x.x.x.x",
  PeerPort => "5000",
  Proto=> "tcp",
  Blocking => "1", 
<-- Tried with blocking (0|1) as well.
 ) or die "ERROR in Socket Creation :
$!\n";

# Ensure we get output right away
$TCPSocket->autoflush(1);

binmode $TCPSocket;### Tried with/without binmode



Similarly, the character encoding of the data on the socket could
> matter. You said there are character codes above 127. Does that
> mean the encoding is 8-bit such as [extended] ASCII or latin1, or
> do you mean the character codes are WAY above 127? Character
> encoding could be another culprit if the \r and \n characters are
> encoded differently in the stream than you (and Perl) expects.
> Using the IO layers or the explicit Encode module you should be
> able to decode the stream into a Perl string that Perl
> understands properly.
>

>From the relevant RFCs:

   The terms "NUL", "TAB", "LF", "CR, and "space" refer to the octets
   %x00, %x09, %x0A, %x0D, and %x20, respectively (that is, the octets
   with those codes in US-ASCII [ANSI1986] and thus in UTF-8 [RFC3629]).
   The term "CRLF" or "CRLF pair" means the sequence CR immediately
   followed by LF (that is, %x0D.0A).  A "printable US-ASCII character"
   is an octet in the range %x21-7E.  Quoted characters refer to the
   octets with those codes in US-ASCII (so "." and "<" refer to %x2E and
   %x3C) and will always be printable US-ASCII characters; similarly,
   "digit" refers to the octets %x30-39.

However, the data stream does contain yEnc content, which as far as I know,
is 8-bit encoding.  So whilst the protocol itself may use UTF-8, the data
transmitted in the protocol can either be UTF-8, or 8-bit

Lines *should* be terminated by CRLF (provided the 8-bit encoding doesn't
mess up the detection), and the entire data stream is then terminated with
a CRLF.CRLF (similar to a SMTP message for example in terms of protocol).



> You can attach an IO layer to the file handle by passing an
> additional argument to binmode:
>
> binmode $fh, ':encoding(UTF-8)';
>
>
Loads, and LOADS and *piles* of UTF-8 errors...

utf8 "\xD826" does not map to Unicode at test.pl line 40 (#1)
utf8 "\x1583F9" does not map to Unicode at test.pl line 40 (#1)
etc.

>From personal experience and using other (nasty) methods and components for
doing what I -should- be able to do with native perl, I've learned the hard
way that messing with binmode $fh, ":encoding" generally corrupts the
8-bit (yEnc) data.  Again, I am more than likely doing it incorrectly, but
I'm really trying to understand how to do it correctly though :-)



> Lastly, you're reading from a socket so there's no guarantee that
> the buffer string is going to necessarily end at the termination
> boundary. Perhaps the protocol guarantees that, but the socket
> surely doesn't. You may need to look for that terminating
> sequence in the middle of the buffer.
>
>
But isn't that exactly why we set things like autoflush(1) or $|=1?  After
the data stream has been sent from the server (i.e. CRLF.CRLF) the server
stops transmitting data and waits for the next command, so there's no
chance that a second data stream may be received by the client socket, at
least not until the client socket issues a new command.



> Does any of that help?
>
>
I appreciate it, truly.  But no, not really :-(  I can honestly say, been
there, done that.

I realize my problem here is the really whacky way in which the data stream
is encoded (and that is completely out of my control).  But there must be a
adequate and proper way to handle this data.


-- 

Regards,
Chris Knipe


Re: reading from socket

2015-08-11 Thread Chris Knipe
On Tue, Aug 11, 2015 at 5:28 PM, John SJ Anderson  wrote:

> On Tue, Aug 11, 2015 at 6:58 AM, John SJ Anderson 
> wrote:
>
>> On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe 
>> wrote:
>>
>>>
>>>
>>> my $numBytesToRead = 512;
>>>
>>> my $buffer;
>>>
>>> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>>>
>>>   if ($buffer =~ m/\r\n\.\r\n$/) {
>>>
>>> print $buffer;
>>>
>>> last;
>>>
>>>   }
>>>
>>> }
>>>
>>>
>>>
>>> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>>>
>>>
>> Don't you need to put $bytesRead into $buffer at some point?
>>
>
> Wow, and this is why we don't review the code before the coffee... 8^/
>


Indeed... read() returns the number of bytes read, not the actual stream of
what HAS been read, unless of course I am again missing something...
http://perldoc.perl.org/functions/read.html

For the above, $bytesRead will be 512.  The stream that is read, is pushed
into $buffer

-- 

Regards,
Chris Knipe


Re: reading from socket

2015-08-11 Thread John SJ Anderson
On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe  wrote:

>
>
> my $numBytesToRead = 512;
>
> my $buffer;
>
> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>
>   if ($buffer =~ m/\r\n\.\r\n$/) {
>
> print $buffer;
>
> last;
>
>   }
>
> }
>
>
>
> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>
>
Don't you need to put $bytesRead into $buffer at some point?

j.


-- 
*John Anderson* • j...@genehack.org • *@genehack* • www.genehack.org
Suck it up, buttercup.


Re: reading from socket

2015-08-11 Thread John SJ Anderson
On Tue, Aug 11, 2015 at 6:58 AM, John SJ Anderson  wrote:

> On Tue, Aug 11, 2015 at 5:24 AM, Chris Knipe  wrote:
>
>>
>>
>> my $numBytesToRead = 512;
>>
>> my $buffer;
>>
>> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
>>
>>   if ($buffer =~ m/\r\n\.\r\n$/) {
>>
>> print $buffer;
>>
>> last;
>>
>>   }
>>
>> }
>>
>>
>>
>> I’m obviously doing this wrong :(  Can anyone perhaps show me the light?
>>
>>
> Don't you need to put $bytesRead into $buffer at some point?
>

Wow, and this is why we don't review the code before the coffee... 8^/

j.


-- 
*John Anderson* • j...@genehack.org • *@genehack* • www.genehack.org
Suck it up, buttercup.


Re: reading from socket

2015-08-11 Thread Brandon McCaig
Chris:

On Tue, Aug 11, 2015 at 02:24:13PM +0200, Chris Knipe wrote:
> Hi All,

Hello,

> I'm reading "binary" from a socket, and just like a normal email message on
> the SMTP protocol (for example), the data is terminated by \r\n.\r\n
> 
>  
> 
> I'm saying "binary" because the data stream does include yEnc data (or
> character codes > 127)
> 
>  
> 
> I'm having issues to exit my read loop when I receive the termination
> characters... 
> 
>  
> 
> my $numBytesToRead = 512;
> 
> my $buffer;
> 
> while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {
> 
>   if ($buffer =~ m/\r\n\.\r\n$/) {
> 
> print $buffer;
> 
> last;
> 
>   }
> 
> }
> 
>  
> 
> I'm obviously doing this wrong :(  Can anyone perhaps show me the light?

I can think of a couple of problems.

Firstly, if the handle isn't being read with binmode set then
perhaps the \r\n are being converted to \n (if this is Windows)?
How are you creating/initializing the socket?

You used to be able to set binary mode on a file handle using
binmode() like this:

binmode $fh;

Similarly, the character encoding of the data on the socket could
matter. You said there are character codes above 127. Does that
mean the encoding is 8-bit such as [extended] ASCII or latin1, or
do you mean the character codes are WAY above 127? Character
encoding could be another culprit if the \r and \n characters are
encoded differently in the stream than you (and Perl) expects.
Using the IO layers or the explicit Encode module you should be
able to decode the stream into a Perl string that Perl
understands properly.

You can attach an IO layer to the file handle by passing an
additional argument to binmode:

binmode $fh, ':encoding(UTF-8)';

Lastly, you're reading from a socket so there's no guarantee that
the buffer string is going to necessarily end at the termination
boundary. Perhaps the protocol guarantees that, but the socket
surely doesn't. You may need to look for that terminating
sequence in the middle of the buffer.

You could use Data::Dumper and/or various poor-man's debugging
techniques to try to identify the problem here. You could write
what you read to a file and inspect that file with a hex editor
afterward. Alternatively, you could invoke perl's debugger with
the -d flag and inspect the program state in real-time.

Does any of that help?

Regards,


-- 
Brandon McCaig  
Castopulence Software 
Blog 
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'



signature.asc
Description: Digital signature


reading from socket

2015-08-11 Thread Chris Knipe
Hi All,

 

I'm reading "binary" from a socket, and just like a normal email message on
the SMTP protocol (for example), the data is terminated by \r\n.\r\n

 

I'm saying "binary" because the data stream does include yEnc data (or
character codes > 127)

 

I'm having issues to exit my read loop when I receive the termination
characters... 

 

my $numBytesToRead = 512;

my $buffer;

while ($bytesRead = read($TCPSocket, $buffer, $numBytesToRead)) {

  if ($buffer =~ m/\r\n\.\r\n$/) {

print $buffer;

last;

  }

}

 

I'm obviously doing this wrong :(  Can anyone perhaps show me the light?

 

--

Chris.