[dancer-users] Only even items

Puneet Kishor punk.kish at gmail.com
Mon Apr 8 21:10:17 BST 2013


And the best one (a revelation for me, at least) is Dancer's DSL

    get '/' => sub { .. };

is really

    my $code = sub { .. };
    get('/', $code);

But the former is more elegant and expressive.


On Apr 8, 2013, at 12:57 PM, Hugues Max <huguesmax at gmail.com> wrote:

> yes, thanks,  this is clearer now
> I'm going to sleep with aspirin.. :-)
> good night
> Hugues
> 
> 
> Le 08/04/2013 21:50, David Precious a écrit :
>> On Mon, 08 Apr 2013 21:39:45 +0200
>> Hugues Max <huguesmax at gmail.com> wrote:
>> 
>>> Thanks you, very much,  It's works
>>> 
>>> but I not really understand why with hash , half of result go to keys
>>> and other to values
>> Basic Perl - a hash is defined as a list of key, value, key, value.
>> 
>> You normally see it written as ( key => value ...), but "=>", the fat
>> comma, is actually syntactically equivalent to a normal comma (with
>> the exception of automatically quoting its left operand), it's just
>> used in this case as it's clearer.
>> 
>> So, the following two are equivalent:
>> 
>> my %hash = ( foo => 'Bar' );
>> my %hash = ( foo, 'Bar' );
>> 
>> The second should make it a little clearer why assigning a list to a
>> hash causes the behaviour you saw.
>> 
>> A little further demonstration in the Perl debugger:
>> 
>>   DB<1> @foo = qw(one two three four);
>>   DB<2> x \@foo;
>> 0  ARRAY(0xa3cb200)
>>    0  'one'
>>    1  'two'
>>    2  'three'
>>    3  'four'
>>   DB<3> %hash = @foo;
>>   DB<4> x \%hash
>> 0  HASH(0xa45a508)
>>    'one' => 'two'
>>    'three' => 'four'
>> 
>> 
>> Does that help make it clearer?
>> 
>> 
>>> and how template toolkit do the relation between database fiels and
>>> values  with simple list ?
>>> 
>>> for my point of view , a simple "complet" example will be good idea
>>> in documentation.
>>> complet = perl part AND ttk part
>> Well, the TT part is out of scope for D::P::D, as you could be using
>> the data for any purpose.
>> 
>> However, what you get is a list of hashrefs; iterating over that in TT
>> tends to look like e.g.:
>> 
>> [% FOR person IN people %]
>>     Hi [% person.name %]!
>> [% END %]
>> 
>> Where "people" is the param name which contains the list of people.
>> 
>> For a quick example having fetched it from a DB, e.g.:
>> 
>>   get '/people' => sub {
>>       my @people = database->quick_select('people', {});
>>       return template 'people', { people => \@people };
>>   };
>> 
>> 
>> Hope that all helps make things clearer for you?
>> 
>> 
> 
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users



More information about the dancer-users mailing list