Gossamer Forum
Home : General : Perl Programming :

Blessing

Quote Reply
Blessing
Will I cause myself any problems using:

bless {}, __PACKAGE__;

instead of:

my $class = shift;
bless {}, $class;

I realise that __PACKAGE__ limits what I can bless whereas with $class = shift it is a bit more flexible, but apart from that it should work right?

Well I know it works because I'm using it, but it's not going to cause me any grief in the future is it?

Last edited by:

Paul: Jul 12, 2002, 9:33 AM
Quote Reply
Re: [Paul] Blessing In reply to
it'll be a problem if you want to do inheritance on the instantiation subroutine, like GT::Base does. Otherwise, nope.

Out of curiosity, why bless {}, __PACKAGE__ though?
Quote Reply
Re: [Aki] Blessing In reply to
>>Out of curiosity, why bless {}, __PACKAGE__ though?
<<

Part of my aim in life is to make my methods/subroutines look as pretty as possible (and I'm lazy)....I like things to align properly and look aesthetically pleasing lol....so out of:

Code:
sub new {
#-----------------------------------------
# Constructor.

return bless {}, __PACKAGE__;
}

....and....

Code:
sub new {
#-----------------------------------------
# Constructor.

my $self = shift;
return bless {}, $self;
}

....I prefer the former.....this is another subroutine I wrote about 10 minutes ago...pretty hey :)

Code:
sub plg_mgr_genie {
#----------------------------------------------------------
# Step 1 of the genie.
#.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:

Support::load('admin_plg_genie_1', { url => my ($url) = $IN->url =~ m|^(http://[^/]+)| } );
}
Quote Reply
Re: [Paul] Blessing In reply to
haha, wooooo ;)

how about this than?


Code:

sub new {
#-------------------------------
# atchoo!!!!
bless &me;
# oh my!
}

# hide this in the deep bowels of your code somewhere
sub me {return ( {}, shift );}

Hahaha, love it, looks like your comments have tinsel on it.

Last edited by:

Aki: Jul 12, 2002, 10:06 AM
Quote Reply
Re: [Aki] Blessing In reply to
LOL..very good :) Paul has a habit of adding silly comments next to things in his code...I think I may have caught it too Crazy

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Paul] Blessing In reply to
Not wanting to get you off topic, but I *hate* tabs in coding. the code for some files is about 3 feet wide if you don't use word wrap.

I deleted the extra spacing & tabs and shaved over 40k off the size of a file.

I'd much rather see:
Code:
<TABLE>
<TR><TD>stuff</TD></TR>
</TABLE>

than:
Code:
<TABLE>
<TR>
<TD>
stuff
</TD>
</TR>
</TABLE>

Okay, I'll get off of your thread now. Tongue
Quote Reply
Re: [Watts] Blessing In reply to
Oh poop. Well in order to keep my code super neat (Im obsessive compulsive about it Wink) then I have stuff like:

Code:
sub plg_mgr_upload {
#----------------------------------------------------------
# Upload a plugin from disk.

my $res = $plg_download->disk_get($IN->param('plugin'));
my $loop = $plg_mgr->loop_uninst;

Support::load('admin_plg_uninstalled',
{
%$res,
uninst_count => scalar @$loop,
uninst_loop => $loop
}
);
}

I guess you'd prefer:

Code:
sub plg_mgr_upload {
#----------------------------------------------------------
# Upload a plugin from disk.

my $res = $plg_download->disk_get($IN->param('plugin'));
my $loop = $plg_mgr->loop_uninst;

Support::load('admin_plg_uninstalled', { %$res, uninst_count => scalar @$loop, uninst_loop => $loop } );
}

?

(Before anyone asks, yes I am working on my own plugin system).

I almost spend as much time lining things up as I do writing the code ..hehe.

I drive myself batty lining up my()'s lol

Code:
my $self = shift;
my $code = shift
my $longer_var = 'needs lining up';