Here I  given example which is working in CGI application.

==============Callback.cgi===============
#!/usr/bin/perl
use Template::Alloy;
use Net::LDAP;

my $tr = Template::Alloy->new(

    EXPOSE_BLOCKS => 1,

    INCLUDE_PATH  => "./",

);

print "Content-type: text/html\n\n";
$tr->process("userlist.tt/header", {title => 'MyStore', date => scalar(localtime)});


sub search_result {
   my ( $mesg, $entry) = @_;

   if ( !defined($entry) ) {
       if ($mesg->count == 0) {
           return;
       }
   }

   my $dn = $entry->dn; # Obtain DN of this entry
   my $cn = $entry->get_value( "cn", asref => 1 );
   my $mail = $entry->get_value( "mail", asref => 1 );
   my $uid = $entry->get_value( "uid", asref => 1 );
   my $vars = {
       dn => "$dn",
       cn => "@$cn",
       mail => "@$mail",
       uid => "@$uid",
   };
   $tr->process("userlist.tt/UserList", $vars);
   $mesg->pop_entry;

}  # End of callback subroutine

$ldap = Net::LDAP->new('localhost') or die "$@";
$ldap->bind(
   dn       => "uid=admin,ou=people,dc=example,dc=co,dc=in",
   password => "admin"
);

$mesg = $ldap->search (
   base   => "dc=example,dc=co,dc=in",
   scope  => "sub",
   filter => "uid=*",
   attrs  => ["dn", "cn", "mail", "uid"],
   callback => \&search_result,
);

if ( $mesg->code ) {
   $errstr = $mesg->code;
   print "Error code:  $errstr\n";
}

$tr->process("userlist.tt/footer", \%row);

=========userlist.tt========
[% BLOCK header ~%]
<html>
 <head>
   <title>my site - [% title %]</title>
 </head>
 <body>
   <h4>The date is [% date %]</h4>
   <table border=1>
     <tr>
       <th>DN</th>
       <th>CN</th>
       <th>Mail</th>
       <th>UID</th>
     </tr>
[% END %]
[% BLOCK  UserList ~%]
     <tr>
       <td>[% dn %]</td>
       <td>[% cn %]</td>
       <td>[% mail %]</td>
       <td>[% uid %]</td>
     </tr>
[% END %]
[% BLOCK footer ~%]
   </table>
 </body>
</html>
[% END %]



Hi all,


I am trying to display the LDAP search entries using 'callback' option in
the search method.
I have been successful in handling the callback option and got 'one by one
result'.
But I found a problem in displaying the search entries in a Template using
the catalyst framework.

I want to display LDAP search entries in TT. But I want to show the search
entries directly.
When I receive the first search result, I want to show it (that result) in
TT and the back-end process should automatically search the second entry
and so on.
Similarly, when I get the second search result, I want  to show that
result in TT and similarly the back-end process should automatically
search the next entry and so on.

It means when I get the search results directly, it should be ideally
displayed in the TT without waiting for all the search results.
For this mechanism, I used the Net::LDAP search method. Search method
provides callback option to return one by one search results.
For the template, I used Template::Alloy module. I used both modules (i.e. Net::LDAP and Template::Alloy) in my CGI application. Both work perfectly.

Now I want to use this mechanism in Catalyst applications as well. I
searched and designed the following module
Catalyst::Helper::View::TT::Alloy. I believe it should work perfectly in
place of the Template::Alloy module. Could you please give your
comments/insights on this as I'm not completely sure about it.

It would also be of immense help if you could refer me some other module
which would/could work in place of the Template::Alloy module perfectly in
the Catalyst framework for different applications.


I would be grateful if any one help me how to access this module with
Catalyst framework.

Looking forward to a prompt response.



--
Venish Khant
www.deeproot.co.in


_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to