Schrift
[thread]413[/thread]

CGI::Application: run_modes (Seite 3)



<< |< 1 2 3 >| >> 29 Einträge, 3 Seiten
esskar
 2005-01-25 00:35
#4211 #4211
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=pktm,22.01.2005, 15:08]Deine Idee würde gehen.[/quote]
nö... sie gehen nicht...

ich glaube, ich bleib bei meiner methode (siehe strat's beitrag)
pktm
 2005-01-25 16:10
#4212 #4212
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
[quote=ptk,24.01.2005, 10:28]Bei CGI::Application gibt es doch einen AUTOLOAD-aehnlichen Mechanismus fuer nicht definierte runmodes, oder?[/quote]
der nennt sich sogar AUTOLOAD und wird wie ein normaler runmode definiert.

Sehr praktisch find ich in diesem Zusammenhang return $other_runmode; - denn so kann man direkt z.B. auf die Startseite oder Ähnliches redirecten ohne den Umweg über den Browser gehen zu müssen.
Ist auch äußerst praktisch bei Passwortgeschützten Seiten.
http://www.intergastro-service.de (mein erstes CMS :) )
pktm
 2005-01-25 16:27
#4213 #4213
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Bei mir geht das (glaube ich):
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
# esskarcgiapp.cgi
#!/Perl/bin/perl

use strict;
use FindBin qw($Bin);
use lib($Bin);
use esskarcgiapp;

my $wapp = esskarcgiapp->new();
$wapp->run();

exit(0);


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# sorry für das kleingeschriebene modul, ist ja nur zum testen
package esskarcgiapp;

use base 'CGI::Application';

 sub cgiapp_prerun {
       my $self = shift;
       # Perform some project-specific init behavior
       # such as to implement run mode specific
       # authorization functions.
       my %loadModules = (
           'login::form' => ['esskarcgiapp_login.pm', 'CGI.pm'],
       );
       my $found = 0;
       foreach( keys(%loadModules) ) {
           if( $_ eq $self->get_current_runmode() ){
               foreach my $module( @{$loadModules{$_}} ) {
                   # überprüfen ob es das Modul gibt und ob das Laden erfolgreich war usw.
                   require $module;
               }
               $found = 1;
               last;
           } # /if
       } # /foreach
       
 } # /cgiapp_prerun

sub setup
{
 my $self = shift;

 $self->header_props(
    -type   => 'text/html',
    -charset   => 'utf-8',
 );

 $self->mode_param('action');
 $self->start_mode('login::form');
 $self->run_modes(
    'login::form' => 'login_form',
 );
}

sub login_form {
   my $lf = new esskarcgiapp_login;
   if( $lf ){
       return "loginfoprm here";
   }else{
       return "geht nicht!?";
   }
}

1;


Code: (dl )
1
2
3
4
5
package esskarcgiapp_login;

use base esskarcgiapp;

1;


Stimmts so?
XX::YY - Module müsste man mittels 'XX/YY.pm' laden können.
mfg pktm
http://www.intergastro-service.de (mein erstes CMS :) )
esskar
 2005-01-25 19:52
#4214 #4214
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
klar... das würd gehen...
ist mir aber zu umständlich!
pktm
 2005-01-25 19:55
#4215 #4215
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
???
Du definierts ganz gemütlich einen Hash den Modulen für die Runmodes in denen du sie brauchst.
Aber wenn du es einfacher haben möchtest, benutze das require doch einfach im runmode login::form, das geht auch.
http://www.intergastro-service.de (mein erstes CMS :) )
esskar
 2005-01-25 20:30
#4216 #4216
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
nein...
mir gefällt es schon nicht, dass die funktionen den output zurück liefern... da staut sich unter umständen viel zu viel speicher an...
esskar
 2005-02-14 00:32
#4217 #4217
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
hab es jetzt doch nochmal mit CGI::Application (bzw. mit CGI::Application::Plus)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Ox::WebMail;

use strict;
use warnings;

use base 'CGI::Application::Plus';
use Ox::WebMail::Consts;

sub cgiapp_get_query {
    require CGI::Simple;

    my $cgi = CGI::Simple->new();
    $cgi->parse_query_string();

    return $cgi;
}

sub setup {
    my $self = shift;

    $self->tmpl_path(&Ox::WebMail::Consts::TEMPLATE_PATH);
    $self->header_props(
        -type      =>    'text/html',
        -charset    =>    &Ox::WebMail::Consts::CONTENT_CHARSET,
    );

    $self->mode_param('action');
    $self->start_mode('login');
    $self->run_modes({
        'login' => sub {
            require Ox::WebMail::Login;
            return Ox::WebMail::Login->new()->run()
        }
    });
}

1;


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Ox::WebMail::Login;

use strict;
use warnings;

use base 'CGI::Application::Plus';

sub setup {
    my $self = shift;

    $self->tmpl_path(&Ox::WebMail::Consts::TEMPLATE_PATH_LOGIN);
    $self->header_type('none');
    $self->mode_param('login');
    $self->start_mode('form');
    $self->run_modes({
        'form' => 'show_form',
    });
}

sub show_form {
    my $self = shift;

    my $tmpl = $self->load_tmpl(
        'form.tpl',
        die_on_bad_params => 0,
        cache => 1
    );


    return $tmpl->output;
}

1;


wenn ich das jetzt laufen lasse, wird die Template-Form (show_form) vor dem HTTP-Header ausgegeben!
Wenn ich anstatt 'CGI::Application::Plus' 'CGI::Application' verwende, wird zuerst dir form, dann den header und dann die form wieder ausgegen... wo ist mein Fehler?\n\n

<!--EDIT|esskar|1108333989-->
esskar
 2005-02-14 00:44
#4218 #4218
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
aha... ich muss
Code: (dl )
$ENV{CGI_APP_RETURN_ONLY} = 1
setzen und dann nach dem haupt-run selbst print sagen!
pktm
 2005-02-14 01:10
#4219 #4219
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Sollte eigentlich immer so eingestellt sein ???
http://www.intergastro-service.de (mein erstes CMS :) )
<< |< 1 2 3 >| >> 29 Einträge, 3 Seiten



View all threads created 2005-01-22 03:40.