Hi stevieb,
thanks for your answer! This looks really good and I tried to integrate this into my code. Yet I still have problems...
I have a subroutine in my program called like this:
sub search_ldap {
+
+
my ( $self, $ldap ) = @_;
# get uid, email, ecufreeze, cnum, itimaccess from LDAP
report LOG_INFO, "Reading from Ldap";
unless (
$ldap->searchUser( filter => '(uid=*)',
attributes => "freeze uid dn cnum emai
+l" ) )
{
report LOG_ERROR, "Can not list user from LDAP: " . $ldap->get
+Error();
exit 0;
}
return $ldap;
}
In this case $ldap is a Utils::Ldap::CompanyLdap object. when calling $ldap->searchUser this object writes the users
into itself. So with the searchUser call, the object itself is altered.
What I tried:
my $m = Mock::Sub->new;
my $ldap = Utils::Ldap::CompanyLdap->new;
+
+
+
my $mocked_sub = $m->mock(
'Utils::Ldap::CompanyLdap::searchUser'
);
# This is actually a Utils::Ldap::CompanyLdap-Object I copied via Data
+::Dumper
my $return_value = bless ( ... );
$mocked_sub->return_value($return_value);
# cache is an instance of my own object
+
ok( $cache->search_ldap($my_ldap) );
ok( $cache->read_all_userids($my_ldap) );
is $mocked_sub->called, 1, "searchUser() called ok";
I was hoping that be putting the object the way I want it to into my return value, the solution would work. The thing is, I noticed searchUser doesn't really return anything, it only appends to the object-instance. So Mock::Sub returns the right thing, but the code continues to work with the old ldap-object. Any Ideas how to solve this?
Greetings and thanks for your insights so far,
yulivee
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.