Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^8: Problem with around BUILDARGS

by saintex (Scribe)
on Apr 22, 2011 at 10:00 UTC ( [id://900795]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Problem with around BUILDARGS
in thread Problem with around BUILDARGS

Hello,
This is the class.

Thank you!

package Selenium2; our $VERSION=0.01; use 5.010; use Moose; use MooseX::NonMoose; use FindBin qw($Bin); use lib ("$Bin/classes","$Bin/classes/browser"); use Test::WWW::Selenium; use WWW::Selenium::Util qw/server_is_running/; extends 'Test::WWW::Selenium'; has 'serverLocation' => (is=>'ro',isa=>'Str',builder =>'buildServerLoc +ation'); sub buildServerLocation { # not: my $self = shift; ?? return "$Bin/lib/selenium-server-standalone-2.0b2.jar" } sub FOREIGNBUILDARGS { my $self = shift; $self->checkServer; my %args = ( @_ == 1 ? %{ $_[0] } : @_ ); $args{serverLocation} //= $self->buildServerLocation; $args{host}//="localhost"; $args{port}//=4444; $args{browser}//='*firefox'; $args{browser_url}//='http://wwww.google.com'; return %args; } sub BUILD { my $self = shift; $self->Browser::BUILD(); $self->start; } sub DEMOLISH { my $self = shift; $self->stop; Browser->DEMOLISH; } sub checkServer { my $self = shift; if (server_is_running) { print "Selenium server running\n"; } else { $self->startServer; } } sub startServer { my $self = shift; defined(my $pid=fork) or die "Cannot fork: $!"; unless ($pid) { eval { exec 'java -jar '.$self->serverLocation; }; die "Impossibile far partire il server selenium: $@\n;" if ($@ +); } sleep(60); #attendi 1 minuto perché il server parta. no Moose; __PACKAGE__->meta->make_immutable; 1; }

Replies are listed 'Best First'.
Re^9: Problem with around BUILDARGS
by stvn (Monsignor) on Apr 23, 2011 at 01:36 UTC

    My best guess based on your code and the error, is that you are calling startServer as a class method, which then calls serverLocation as a class method instead of an instance attribute accessor, which means it wont be initialized.

    -stvn
      Hello,
      thank you for your suggestion:
      and how can I force serverLocation to be an instance and not a class method?
Re^9: Problem with around BUILDARGS
by Anonymous Monk on Apr 29, 2011 at 08:09 UTC
    Another solution sould be to use MooseX::ClassAttribute.

    You could then define : class_has 'defaultServerLocation' => (is => 'ro', isa => 'Str', builder =>'buildDefaultServerLocation' );

    cpk
      I have tested this solution and it works.

      However the builder must be lazy (lazy => 1) in order to be correctly initialized in the FOREIGNBUILDARGS sub.

      But I don't know why...

      Any idea ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://900795]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found