Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear Monks,

I am playing with Inside-Out Classes and trying to do Inheritance, but not sure how to use hash-references within Objects of a Inside-Out class. An example class like so:

package Samba::LDAP; use version; $VERSION = qv('0.0.1'); use warnings; use strict; use Carp; use Class::Std::Utils; use File::Basename; use base qw(File::Samba); { # Attributes my %config_of; # Constructor takes the path of the Samba config file sub new { my ($class, $samba) = @_; # Bless a scalar to instantiate the new object... my $new_object = bless anon_scalar(), $class; # Initialise the object's "config" attribute... $config_of{ident $new_object} = $samba; return $new_object; } sub get_path { my ($self) = @_; return $config_of{ident $self}; } sub get_filename { my ($self) = @_; my $filename = basename($config_of{ident $self}); return $filename; } } 1;
And the client code I've written is like so:
use strict; use warnings; use Samba::LDAP; my $smbconf = Samba::LDAP->new(q{/etc/samba/smb.conf}); # path is loaded my $path = $smbconf->get_path(); print "$path\n"; my $filename = $smbconf->get_filename(); print "$filename\n"; my @shares = $smbconf->listShares(); print "@shares\n";

No you can see my problem, listShares(); is part of File::Samba, which is hash based. My program output is:

[ghenry@perlbox lib]$ perl ../scripts/test.pl /etc/samba/smb.conf smb.conf Not a HASH reference at /usr/lib/perl5/site_perl/5.8.6/File/Samba.pm l +ine 181.
So the listShares method of File::Samba expects the object to be a hash reference. How can I provide this?

Thanks and feel free to give me a slap if this is something trivial! ;-)

Gavin.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!

2005-11-16 Retitled by planetscape, as per Monastery guidelines
Original title: 'How to use Inheritance with Inside-Out Classes and Hash Bassed Classes'


In reply to How to use Inheritance with Inside-Out Classes and Hash Based Classes by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2022-10-04 14:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (17 votes). Check out past polls.

    Notices?