Permalink
Browse files

Fixed a few bugs in the original conversion (TODO: %options)

  • Loading branch information...
1 parent 06a15dc commit 58bf2ffa20ae68daba35917fb94198e689c8697e @cosimo committed Nov 21, 2010
Showing with 38 additions and 11 deletions.
  1. +32 −9 lib/Facter.pm
  2. +6 −2 lib/Facter/Util/Collection.pm
View
41 lib/Facter.pm
@@ -31,6 +31,7 @@ use Facter::Util::Fact;
use Facter::Util::Collection;
our $VERSION = '0.02';
+our $LAST_OBJECT;
# TODO: RT#77906
#%*ENV<LANG> = 'C';
@@ -50,6 +51,10 @@ method version () {
return $VERSION
}
+method BUILD {
+ $LAST_OBJECT = self;
+}
+
multi method debugging () {
return $!debug != 0
}
@@ -108,7 +113,7 @@ method flush(*@args) {
self.collection.flush(@args);
}
-method value(*@args) {
+method value (*@args) {
self.collection.value(@args);
}
@@ -118,17 +123,35 @@ method value(*@args) {
# });
#}
-for 'list', 'to_hash' -> $name {
- Facter.^add_method($name, method (*@args) {
- self.collection.load_all();
- self.collection.$name.(@args);
- });
+#for 'list', 'to_hash' -> $name {
+# Facter.^add_method($name, method (*@args) {
+# self.collection.load_all();
+# self.collection.$name.(@args);
+# });
+#}
+
+method list (*@args) {
+ self.collection.load_all();
+ self.collection.list(@args);
+}
+
+method to_hash (*@args) {
+ self.collection.load_all();
+ self.collection.to_hash(@args);
}
# Add a resolution mechanism for a named fact. This does not distinguish
# between adding a new fact and adding a new way to resolve a fact.
-method add ($name, %options = (), &block) {
- self.collection.add($name, %options, &block)
+method add ($name, Sub $block) {
+ # TODO add %options support
+ #multi method add ($name, %options = (), $block) {
+ my $instance = self // Facter.get_instance;
+ $instance.collection.add($name, $block);
+}
+
+method get_instance {
+ if self { return self }
+ $LAST_OBJECT //= Facter.new;
}
method each {
@@ -155,7 +178,7 @@ method warn ($msg) {
}
method reset {
- @!collection = ();
+ $!collection = ();
}
# Load all of the default facts, and then everything from disk.
View
8 lib/Facter/Util/Collection.pm
@@ -18,8 +18,12 @@ method get($name) {
# Add a resolution mechanism for a named fact. This does not distinguish
# between adding a new fact and adding a new way to resolve a fact.
-method add($name, %options = (), Sub $block) {
- $name = $.canonize($name);
+method add($fact_name, Sub $block) {
+
+ # TODO add %options support
+ my %options = ();
+
+ my $name = self.canonize($fact_name);
my $fact = %!facts{$name};
unless $fact {

0 comments on commit 58bf2ff

Please sign in to comment.