Not to dispute anything you are suggesting, but more to explain how I got there. Before
mkBless (something I came up with on the fly while writing there -- not always my
best work -- BREAK--- Just as an FYI why I seem to go away for a while in middle of
conversations. My typing speed has decayed something fierce over the years...like down to 20-30% of faster times. No way can my typing keep up with my thoughts these days so sometimes blocks of explanatory text are skipped -- confusing readers and myself. But sigh.... In case someone
doesn't know, use mem allows me to mostly easily include a bunch of packages in 1 files.
somwhere further above:
{ package RPM_data; #{{{
use constant D => q(-); #D for Dash
use constant o => q(.); #o for dot
use Data::Vars [qw(N V R A reldir reponame cpeids size)],
{cpeids=>sub{ {} } }; # N-keys of this is ref-cnt
sub cpeids() { my $p = shift;
scalar keys %{$p->{cpeids}} }
sub cpeid(;$) { return q(cpeid) unless @_;
my $p = shift;
my $cpeid = shift;
mkARRAY $p->cpeids;
push @{$p->cpeids}, $cpeid;
my $cpeids = ErV $p, cpeids;
push @{$p->cpeids}, $cpeid unless ErV $cpeids, $cpeid;
return $p->cpeids($cpeid);
}
sub new($) { my $p = shift; my $c = ref $p || $p;...}
sub new_from_file($) { my $p = shift; my $fname = shift; ...
sub new_from_path($) { my $p = shift; my $pthnam = shift;...
sub VR () { my $p = shift; $p->{V} .D. $p->{R} }
sub NVR () { my $p=shift; $p->{N} .D. $p->VR }
sub NVRA () { my $p=shift; $p->NVR .o. $p->{A} }
sub relpth() {my $p = shift; pathcat($p->reldir, $p->NVRA .o."rpm")}
}#####
{ package VRs; #{{{
use Types::Core qw(blessed LongSub);
use Data::Vars [qw(VRs)], {VRs=>sub{ {} }};
use P; use Dbg(1,1,1);
sub vr($;$) { my $p = shift; my $c = ref $p || $p;
my $argp = shift;
my $vr = ErV $argp, VR;
my $vrp;
if (@_) {
$p->{VR}{$vr} = RPM_data->new(shift);
}
$p->{VR}{$vr}; }
1;} #}}}
######
(somewhere above:
{ package RepoVData; #{{{
use strict; use warnings;
use mem;
use Data::Vars [qw(RepoDB RepoXMLs )], #RDFile_inf
{ RepoXMLs => sub() { {} }, # HASH{type => RDFil
+e_inf}
RepoDB => sub() { {} }, }; # nam=>rpmdata
And then a bunch of these progresssive assignments checking to see if each
section is blessed. This started getting very repetitive and ugly looking.
$p->{Vcpeid}{$cpeid} = RepoVData->new() unless blessed $p->{Vcpeid}{$c
+peid};
$p->{Vcpeid}{$cpeid}{RepoDB} = RepoDB->new() unless blessed $p->{Vcpei
+d}{$cpeid}{RepoDB}
$p->{Vcpeid}{$cpeid}{RepoDB}{$nam} = VR->new() unless
blessed $p->{Vcpeid}{$cpe
+id}{RepoDB}{$nam};
$p->{Vcpeid}{$cpeid}{RepoDB}{$nam}{vr($V, $R) = RPM_data->new({...}) u
+nless blessed
$p->{Vcpeid}{$cpeid}{RepoDB}{$na
+m}{vr($v, $R) ....
This is where I saw I had:
lvalue = new addon unless blessed lvalue;
That's where mkBless came in -- to check if the levalue was blessed, and if so,
assign more of the data-to-follow onto it.
I had it return a value so I could skip some repetition at the beginning of
each line.
So, call that a class factory if you want, I'm not sure it is, but at least
wanted you to see how it "fell out of" progressively adding on more data to walk through this DB.
(is there anyway to insert a picture or diagram in this chaos? as it might help me
clarify where I'm going....the old pic is worth a thousand words thing.
Thanks for the feedback so far, I won't be annoyed if anyone dropps out of this mess, I sorta
wish I could, but it stuff I need to get done to manage my system, UG.
cheers!...oh and the bit about doing that
"blessed test or return less work" bit, I probably would have gotten there eventually, in some later cleanup -- I put focus first on getting something to work -- and yes, I am one of those who keeps working at things to clean them up and make them better. -- because if I know
I need to do that for my "future self" (if no one else)
to able to reuse the code I write today.
|