<commit_before>package XML::FeedPP::MediaWords;

##
#  This class is a wrapper to work around bugs in XML::FeedPP
#  XML::FeedPP does not provide a way to grab the <content> element from RSS feeds
#  It will only provide the <description> element which often has a summary instead of the full text
#
#  We wanted to sub class XML::FeedPP but XML::FeedPP cannot be subclassed so we have to use AUTOMETHOD to fake subclassing it.
#
##
use strict;
use warnings;
use Perl6::Say;
use Data::Dumper;
use XML::FeedPP;

use Class::Std;
{

    my %feedPP : ATTR;

    sub BUILD
    {
        my ( $self, $ident, $arg_ref ) = @_;

        my $content = $arg_ref->{ content };
        my $type    = $arg_ref->{ type };

        my $fp;
        eval { $fp = XML::FeedPP->new( $content, -type => $type ); };

        $feedPP{ $ident } = $fp;
    }

    sub _wrapper_if_necessary
    {
        my ( $obj ) = @_;

        return $obj if ( !$obj->isa( 'XML::FeedPP::RSS::Item' ) );

        return XML::FeedPP::RSS::Item::MediaWords->create_wrapped_rss_item( $obj );
    }

    sub get_item
    {
        my $self = shift;

        my @args  = @_;
        my @items = $feedPP{ ident $self}->get_item( @args );

        my @ret = map { _wrapper_if_necessary( $_ ) } @items;

        if ( defined( $args[ 0 ] ) )
        {
            return $ret[ 0 ];
        }
        elsif ( wantarray )<commit_msg>Make the constructor die if the creation of the wrappered XML::FeedPP object also fails.<commit_after>package XML::FeedPP::MediaWords;

##
#  This class is a wrapper to work around bugs in XML::FeedPP
#  XML::FeedPP does not provide a way to grab the <content> element from RSS feeds
#  It will only provide the <description> element which often has a summary instead of the full text
#
#  We wanted to sub class XML::FeedPP but XML::FeedPP cannot be subclassed so we have to use AUTOMETHOD to fake subclassing it.
#
##
use strict;
use warnings;
use Perl6::Say;
use Data::Dumper;
use XML::FeedPP;

use Class::Std;
{

    my %feedPP : ATTR;

    sub BUILD
    {
        my ( $self, $ident, $arg_ref ) = @_;

        my $content = $arg_ref->{ content };
        my $type    = $arg_ref->{ type };

        my $fp;
        eval { $fp = XML::FeedPP->new( $content, -type => $type ); };

        $feedPP{ $ident } = $fp;

	if ( $@ )
	{
	    my $err_mesg = $@;
	    die "XML::FeedPP->new failed: $err_mesg";
	}
    }

    sub _wrapper_if_necessary
    {
        my ( $obj ) = @_;

        return $obj if ( !$obj->isa( 'XML::FeedPP::RSS::Item' ) );

        return XML::FeedPP::RSS::Item::MediaWords->create_wrapped_rss_item( $obj );
    }

    sub get_item
    {
        my $self = shift;

        my @args  = @_;
        my @items = $feedPP{ ident $self}->get_item( @args );

        my @ret = map { _wrapper_if_necessary( $_ ) } @items;

        if ( defined( $args[ 0 ] ) )
        {
            return $ret[ 0 ];
        }
        elsif ( wantarray )
{'fraction_non_alphanumeric': 0.13617747440273037, 'fraction_numerical': 0.0020477815699658703, 'mean_word_length': 2.3612385321100917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4983722', 'n_tokens_mistral': 1016, 'n_tokens_neox': 966, 'n_words': 310}