=encoding utf8 =head1 NAME OpenResty::Tutorial::GettingStarted::Perl - Zero to OpenResty for Perl programmers =head1 DESCRIPTION This tutorial should give you everything you need to start with an OpenResty account using Perl. =head1 Prerequisites =over =item An OpenResty account You should already have an account on an OpenResty server. You can either set up an OpenResty server on your own machine or just request an account on our Yahoo! China's production server by sending an email to C. If you're running your own instance of the OpenResty server, you can use the following command to create an account (named C) for yourself: $ bin/openresty adduser foo You'll be prompted to enter a password for the C role of your C account. Throughout this tutorial, we'll assume you own an account named C whose C role's password is C. And the account belongs to the server C. =item L Because OpenResty's API is totally RESTful, that is, it's totally HTTP based. So it's completely okay to directly use a general HTTP client libary like L. But to make things even easier, we'll stick with a CPAN module, L, throughout the tutorial. In case you don't know, installing the L module is as simple as $ sudo cpan WWW::OpenResty::Simple Commands will differ slightly if you're on Win32: C:\>cpan WWW::OpenResty::Simple =back Note that if you use an account on others' OpenResty servers (like ours), you need I install the hairy L module on CPAN. =head1 Login There's various different ways to login to your OpenResty account. But in a Perl script, we usually use the default L role with full priviledges: use strict; use warnings; use utf8; use WWW::OpenResty::Simple; my $resty = WWW::OpenResty::Simple->new( { server => 'api.openresty.org' } ); $resty->login('foo', 'hello1234'); The first statement loads the L module which we'll be using exclusively to manipulate our account. And in the second one, we created an instance of the L class with the domain of the OpenResty server we're using. It might be a different value on your side (i.e. C) if you're running your own instance of server. It's not good practice to hard code your password explicitly in your scripts. I wrote the sample code this way merely for the demonstration purpose. =head1 Just Mudding Around Usually we use OpenResty as a RESTy database. As with traditional relational database systems like mysql and PostgreSQL, we start by creating a "data schema". In OpenResty, C often resembles database tables (but they could be something else as well). You can define a new C like this: $resty->post( '/=/model/Post', { description => 'blog posts', columns => [ { name => 'author', default => 'Anonymous' }, { name => 'title', default => 'No title' }, { name => 'content' }, { name => 'created', type => 'timestamp (0) with time zone', default => ['now()'] }, { name => 'comments', type => 'integer', default => 0 } ] } ); L objects' C method will issue an HTTP C command behind the scene. =head1 Importing huge amount of data =head1 Sharing your data with others =head1 Keeping a data backup at your localhost =head1 Where to go from here =head1 AUTHOR Agent Zhang (agentzh) C Copyright (c) 2007 by Yahoo! China EEEE Works, Alibaba Inc.